Capturing stdout incrementally

Moosebumps moosebumps at moosebumps.com
Sat Apr 3 16:06:17 EST 2004


I have a large set of Python scripts that interface with command line
utilities (primarily Perforce).  I am currently capturing ALL the text
output in order to get results and such.  I am using the popen functions to
get the stdout, stderr streams.

However, some of the operations take a really long time (copying large files
over the network).  If you run Perforce directly (or through os.system,
which doesn't return text output), it shows which files are getting copied,
one at a time.  However, if I'm calling it through Python's popen, it
appears to hang while it copies all the files, then suddenly all the text
output appears at once after the operation is done.

Does anyone know a way around this?  It is problematic because people think
that the program has hung, when it is really just taking a long time.  I
would like the normal stdout to be printed on the screen as it is normally
(but also captured by my Python script simultaneously).

I am on Windows by the way, so the utilities are printing to the windows
command shell.

thanks for any advice,
MB





More information about the Python-list mailing list