Fetching the stdout & stderr as it flows from a unix command.

Matt Leslie matthewleslie at hotmail.com
Fri Jun 4 15:24:43 EDT 2004


Hans Deragon wrote:
> Greetings.
> 
> 
> I am performing:
> 
>   commands.getstatusoutput("rsync <params>");
> 
> rsync takes a long time and prints out a steady stream of lines
> showing which file it is currently working on.
> 
> Unfortunatly, the commands.getstatusoutput() fetchs everything and
> there is no way to ask it to copy the output of the command to
> stdout/stderr.  Thus when rsync takes an hour, I have no clue where it
> is at.
> 
> Anybody has a suggestion how to let stdout/stderr print out on the
> console when calling a unix command?
> 

Perhaps you could use the popen2 module. popen2.popen2() returns file 
handles for stdout and stderr. You could read from these and print the 
output to the screen while the process runs.

Matt



More information about the Python-list mailing list