Re: [Windows] Sending CTRL-C event to console application



En Thu, 08 Feb 2007 15:54:05 -0300, Daniel Clark <djbclark@xxxxxxxxx> 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

.



Relevant Pages

  • Re: Sending CTRL-C event to console application
    ... cleanly if it sees "CTRL-C" on the console. ... "Only those processes in the group that share the same console as the ... I'm going to try taking a different approach by using a GUI Automation ... WATSUP - Windows Application Test System Using Python ...
    (comp.lang.python)
  • service and SetConsoleCtrlHandler
    ... console process for debugging). ... some random time due to call to HandlerRoutineroutine. ... Aha, just now I realized, that Windows is most probably calling Ctrl-C to ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Send ctrl-c
    ... | If your app is a console app the console receives the key events and sends ... cntrl-c at the c:\ prompt will just bring you to another prompt and not ... And if you do dir /s and do a ctrl-c, ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: AppDomain.CurrentDomain.ProcessExit && CTRL-C
    ... The good news is, if you move to V2.0, ... > We've got a handler on Console now, to catch Ctrl-C, so we can deal with ...
    (microsoft.public.dotnet.framework.clr)
  • RE: AppDomain.CurrentDomain.ProcessExit && CTRL-C
    ... The good news is, if you move to V2.0, ... We've got a handler on Console now, to catch Ctrl-C, so we can deal with ...
    (microsoft.public.dotnet.framework.clr)