Sending <Ctrl-C> to a process opened from popen()

M

Marc

Hi all,

In searching for an answer to this problem I found several solutions
dealing with Unix but none dealing with Windows. Basically I want to
send a ping for an indefinite period of time, stop it at some point,
and then read the results. I open up a ping process using popen().

I found ways to send a break signal using signal module, but for that
I need the PID. All the ways described in the newsgroups for finding
PID were for UNIX.

So how do I find the PID of a spawned process in Windows to send a
break signal?

Thanks ahead of time,
Marc
 
T

Trent Mick

[Marc wrote]
Hi all,

In searching for an answer to this problem I found several solutions
dealing with Unix but none dealing with Windows. Basically I want to
send a ping for an indefinite period of time, stop it at some point,
and then read the results. I open up a ping process using popen().

I found ways to send a break signal using signal module, but for that
I need the PID. All the ways described in the newsgroups for finding
PID were for UNIX.

So how do I find the PID of a spawned process in Windows to send a
break signal?

You want to use the Win32 API method GenerateConsoleCtrlEvent:

http://msdn.microsoft.com/library/d...-us/dllproc/base/generateconsolectrlevent.asp

The PyWin32 extensions (comes with ActivePython, can be installed
separately on other Python distros) provide access to this:

win32api.GenerateConsoleCtrlEvent(win32con.CTRL_C_EVENT, pid)

But you need to get the pid for that. You already have the PID if you
started a process with CreateProcess, but you are using popen, which
hides those details. I don't know an easy way to get the PID.

I have a process.py module which will spawn a process and return a
object represent it with attributes for stdin/stdout/stderr and methods
to .wait(), .kill(). This might be more helpful to you, but my
process.py is not perfect by any stretch.
http://starship.python.net/~tmick/#process

Cheers,
Trent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top