Win32 CreateProcess with In/out Redirection and a Way to kill the job?

Vassilis Virvilis vasvir at iit.demokritos.gr
Sat Feb 3 09:13:24 EST 2001


Michael Jonas wrote:
> 
> Seems like I need people with win32 geek factor....
> 
> What I want:
> I'd like to code a extension module with a function popen3 (same as in os)
> and a function is_alive() and terminate().
> 
> What I allready have:
> a module which has an popen3 method which does exactly the same like the
> posixmodule popen3 except that I extracted it to get hold of the process
> Handle (from the normally inaccessible dict). The redirection works fine, I
> can check if the job is still alive with my new is_alive(<file>). But I'm
> really struggling to terminate the job.
> 
> Where my proble is:
> The CreateProcess in the popen3 not only starts the job specified, it first
> starts a cmd.exe which then starts the job. Ergo: the process handle I save
> is the handle of the console app. The started app does not care at all if I
> do a TerminateProcess on the console. The cmd.exe dies and the started job
> stays alive. I tried to find a way to get hold of the Window Handle of the
> console, but did not find a way. (The doughter process seems to die if I
> close the Console Window. So I thought I could send a WM_Close to the
> Window....) Nothing really worked till here...
> 
> Any idea how to implement something like this on Win32?!?
> 
> Thanks Michel
> 
> PS. Please cc the mail also to mj at muc.das-werk.de, cause I'm having trouble
> getting the mail from the list.

I don't know how exactly the popen* functions are implemented but I
think it's better to use CreateProcess/DuplicateHandle to mimic the
popen* behavior in windows and fork/dup in UNIX.

PS
In UNIX a libc popen invocation fires a shell also (bin/sh).

	.Bill



More information about the Python-list mailing list