Joining stdout & stderr of subprocess ?

Duncan Booth duncan.booth at invalid.invalid
Fri Apr 21 08:07:00 EDT 2006


robert wrote:

> 
> when I run a command
> 
> myapp 2>&1
> 
[ I guess you meant to say here that the stdout, stderr output was 
interleaved ]
> 
> yet:
> 
> #!python
> print os.popen("myapp 2>&1").read()
> 
> the stderr stuff comes all after the stdout stuff.
> How can I get ahold of all the out and err joined synchronously in the 
> order, it is created ?
> 
I think what is happening here is that in the first case the output is to a 
terminal, so myapp doesn't buffer its output. In the second case the output 
isn't going to a terminal so myapp is buffering it and only produces output 
when the buffer is full. Probably there isn't sufficient stderr output to 
force any out until myapp terminates, so you get it all at the end.

Probably the only way to get the output interleaved is to change myapp so 
that it doesn't buffer its output or so it sends all of its output to a 
single stream.



More information about the Python-list mailing list