[Windows] Sending CTRL-C event to console application
Gabriel Genellina
gagsl-py at yahoo.com.ar
Thu Feb 8 21:12:55 EST 2007
En Thu, 08 Feb 2007 15:54:05 -0300, Daniel Clark <djbclark at gmail.com>
escribió:
> I have a Windows command line based application that only shuts down
> cleanly if it sees "CTRL-C" on the console. I need to automate the
> running of this application, but still allow the user sitting at the
> machine to cancel the process cleanly if he/she needs to. In Unix this
> would be a tiny shell script that used "kill -15", but under Windows
> there does not seem to be an easy way to do this, at least that I can
> find.
>
> Below is a test program, based on CreateProcess.py from "Python
> Programming on Win32". The
> win32api.GenerateConsoleCtrlEvent(win32con.CTRL_C_EVENT, pid) lines
> don't seem to do anything. What they should do is nothing in the case
> of notepad, and exit out of the dir builtin process in the case of the
> cmd.exe process.
>
> Any ideas on how to make this work?
From your process creation code:
> CreationFlags = win32process.CREATE_NEW_CONSOLE | \
> win32process.CREATE_NEW_PROCESS_GROUP | \
> win32process.NORMAL_PRIORITY_CLASS
From http://msdn2.microsoft.com/en-us/library/ms683155.aspx
"Only those processes in the group that share the same console as the
calling process receive the signal. In other words, if a process in the
group creates a new console, that process does not receive the signal, nor
do its descendants."
Maybe you have better luck on a Windows programming group, asking how to
send a Ctrl-C event (or a SIGINT signal) to another process attached to a
different console.
--
Gabriel Genellina
More information about the Python-list
mailing list