Capturing stdout incrementally

Josiah Carlson jcarlson at uci.edu
Wed Apr 7 00:43:10 EDT 2004


>>>I am on Windows by the way, so the utilities are printing to the windows
>>>command shell.
>>
>>By default, popen in Windows buffers everything coming from the called
>>app.  I believe you can use various Windows system calls in pywin32 in
>>order to get line buffered output, but I've never done it, so have
>>little additional advice other than "check out pywin32".
> 
> 
> Typically this behavior on Windows (and at least in my experience on
> Unix) comes not from popen buffering its input from the called
> program, but the called program buffering its output when it isn't a
> normal console.  I'm not sure if this is default behavior from the C
> library, but it's particularly true of cross-platform code that often
> uses isatty() to check.

Your experience in unix has colored your impression of popen on Windows. 
  The trick with Windows is that pipes going to/from apps are not real 
file handles, nor do they support select calls (Windows select comes 
from Windows' underlying socket library).  If they did, then the Python 
2.4 module Popen5 would not be required.

Popen5 is supposed to allow the combination of os.popen and os.system on 
all platforms.  You get pollable pipes and the signal that the program 
ended with.  As for how they did it on Windows, I believe they are using 
pywin32 or ctypes.

  - Josiah



More information about the Python-list mailing list