Capturing stdout from a console process?

Dave Brueck dbrueck at edgix.com
Thu Dec 14 21:53:13 CET 2000


Hi Sam,

Use the os.popen* functions:

import os
w,r = os.popen4('xcopy c:*.* d: /v')
print r.read() # Prints stdout and stderr results of your command

-Dave

> -----Original Message-----
> From: python-list-admin at python.org
> [mailto:python-list-admin at python.org]On Behalf Of Sam Schulenburg
> Sent: Thursday, December 14, 2000 12:59 PM
> To: python-list at python.org
> Subject: Capturing stdout from a console process?
> 
> 
> I am using <os.system("xcopy c:*.* d: /v")> within a python program to
> copy files from one directory to another under windows NT. When the
> program executes, a new console window is created with the results of
> the xcopy command being displayed in the console window. Is 
> their a way
> to capture this output by python so I can log error messages?
> 
> Sam Schulenburg
> 
> 
> Sent via Deja.com
> http://www.deja.com/
> -- 
> http://www.python.org/mailman/listinfo/python-list




More information about the Python-list mailing list