On Feb 8, 9:12 pm, "Gabriel Genellina" <[EMAIL PROTECTED]> wrote: > En Thu, 08 Feb 2007 15:54:05 -0300, Daniel Clark <[EMAIL PROTECTED]> > 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 > > Fromhttp://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."
Thanks, although I'm 99% sure I've also tried it without CREATE_NEW_CONSOLE (with a process that should just die if sent CTRL- C, so it was monitorable via Task Manager) and it still didn't work. I'm going to try taking a different approach by using a GUI Automation tool like WATSUP [1] or pywinauto[2] next. > 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. >From what I've found via Google [3], Windows has no real concept of signals, and no equivalent to SIGINT. [1] WATSUP - Windows Application Test System Using Python http://www.tizmoi.net/watsup/intro.html [2] pywinauto - Python Win32 Automation http://www.openqa.org/pywinauto/ [3] how to send a SIGINT to a Python process? http://mail.python.org/pipermail/python-list/2005-October/343461.html -- http://mail.python.org/mailman/listinfo/python-list