subprocess.Popen and ordering writes to stdout and stderr
Mark Hammond
skippy.hammond at gmail.com
Thu Dec 17 18:23:33 EST 2009
On 18/12/2009 9:33 AM, Chris Withers wrote:
> exarkun at twistedmatrix.com wrote:
>> libc is probably giving you line buffering when you use os.system
>> (because the child process inherits the parent's stdio, and the
>> parent's stdio is probably a pty, and that's the policy libc implements).
>
> <snip>
>
> Interesting, but do these assertions still hold true when I tell you
> that I'm doing all this on Windows? ;-)
Yep. You can see similar behaviour from just the cmd-prompt and the
following script:
--
import sys
for i in range(10):
print "stdout"
print >> sys.stderr, "stderr"
--
If you execute it "normally" from a command-prompt, you will see things
written in the correct order. If you execute it like 'python foo.py >
out 2>&1', the order will be mixed up. If you execute it like 'python
-u foo.py > out 2>&1' the order is restored.
HTH,
Mark
More information about the Python-list
mailing list