Author ggenellina
Recipients ggenellina, pmezard
Date 2007-11-07.15:48:50
SpamBayes Score 0.015052
Marked as misclassified No
Message-id <1194450531.49.0.208562179266.issue1366@psf.upfronthosting.co.za>
In-reply-to
Content
(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.
History
Date User Action Args
2007-11-07 15:48:51ggenellinasetspambayes_score: 0.015052 -> 0.015052
recipients: + ggenellina, pmezard
2007-11-07 15:48:51ggenellinasetspambayes_score: 0.015052 -> 0.015052
messageid: <1194450531.49.0.208562179266.issue1366@psf.upfronthosting.co.za>
2007-11-07 15:48:51ggenellinalinkissue1366 messages
2007-11-07 15:48:50ggenellinacreate