[issue1366] popen spawned process may not write to stdout under windows
Gabriel Genellina
report at bugs.python.org
Wed Nov 7 16:48:51 CET 2007
Gabriel Genellina added the comment:
(I think the title you meant was
"popen spawned process may not
write to stderr under windows")
The child is dying with IOError:
[Errno 22] Invalid argument
at the sys.stderr.flush() call.
Neither the docs for os.popen nor
the Linux man page for popen(3)
say that stderr is redirected, so
one would expect the handle to be
inherited; the IOError looks like
a bug.
Try using os.popen4 or
popen2.popen4 or -the recommended
choice- the subprocess module.
Using the latter, this is the
modified parent.py:
"""
import subprocess
cmd = 'python child.py'
p = subprocess.Popen(cmd,
stdout=subprocess.PIPE)
for line in p.stdout:
print ">>>", line,
print p.wait()
"""
and this is the output, as
expected:
"""
2:stderr
>>> 1:stdout
>>> 3:stdout
0
"""
Note the 2:stderr line lacking the
>>>, because it was printed
directly by the child process onto
the stderr handle inherited from
its parent.
----------
nosy: +gagenellina
__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue1366>
__________________________________
More information about the Python-bugs-list
mailing list