[python-win32] Control-C

Mark Hammond mhammond at skippinet.com.au
Fri Oct 14 00:22:18 CEST 2005


> I've looked around, but I wasn't able to find anything about this
> issue.  I am writing an application that calls a separate windows
> application as a process.  That's not a problem, I can get it to run and
> do what it needs to do.  However, the normal way to stop the separate
> windows application is to hit CTRL-C.  That allows it to end and do
> finishing processes.  Is there a way to send a CTRL-C signal to a
> process?  I tried simply doing a TerminateProcess on the process, as
> suggested to me earlier, however, this doesn't allow the normal cleanup
> operations to do what they need to do.  Any help you might have would be
> greatly appreciated.

Sadly, I think GenerateConsoleCtrlEvent will not work for you.  In short, it
is nearly useless :) The description of the function says it "sends a
specified signal to a console process group that shares the console
associated with the calling process" and it means it literally.  In your
case, it sounds like you have a GUI program, so that will not have a
console, so will never be able to be part of your process group.  If the
running program is not in the exact same console as your app, you are hosed.

More info on this can be found at
http://www.microsoft.com/msj/0698/win320698.aspx, where they describe a
technique where they need to use another child process to make this work -
but even then its not clear it would work if you app is a GUI one.

hrm - re-reading your message above, it sounds like the child process *is* a
console process.  Either way, the above should get you in the right
direction.

Mark



More information about the Python-win32 mailing list