469,920 Members | 2,377 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,920 developers. It's quick & easy.

Run child process with stdout and result on Win32?

Is there really no way to run a sub-process, gather its stdout/stderr,
and collect the return-code, on Win32???
But that's what the docs say...
These methods do not make it possible to retrieve the return code
from the child processes. The only way to control the input and
output streams and also retrieve the return codes is to use the
Popen3 and Popen4 classes from the popen2 module; these are only
available on Unix.


Surely not!?!?

Dave.

Jul 18 '05 #1
1 1958
Dave Sellars <da**@didnt.freeserve.co.uk> wrote in
news:40***********************@news.easynet.co.uk:
Is there really no way to run a sub-process, gather its stdout/stderr,
and collect the return-code, on Win32???
But that's what the docs say...
These methods do not make it possible to retrieve the return code
from the child processes. The only way to control the input and
output streams and also retrieve the return codes is to use the
Popen3 and Popen4 classes from the popen2 module; these are only
available on Unix.


Surely not!?!?

Dave.


Bizarrely, the return code is returned as the result of the *last* call to
the close method on any of the file handles returned. i.e. You must close
all of stdin, stdout and stderr handles returned (usually after
reading/writing), and the last one you close will return a numeric exit
code if the command returned a non-zero exit code. If the command returned
a 0 exit code then the final close returns None.
from popen2 import popen2
fout, fin = popen2("dir c:\\temp")
print fout.close(), fin.close() None None fout, fin = popen2("dir c:\\xxx")
print fout.close(), fin.close() None 1 fout, fin = popen2("dir c:\\xxx")
print fin.close(), fout.close() None 1


So far as I can see, the documentation omits to mention this little fact (I
read the source).
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Mike Finister | last post: by
2 posts views Thread by Greg Ercolano | last post: by
22 posts views Thread by Jason Zheng | last post: by
reply views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.