Capturing output from stderr

Klaus Alexander Seistrup klaus at seistrup.dk
Mon Dec 5 08:34:24 EST 2005


Doru-Catalin Togea wrote:

> On solaris, I call a program from python with
>
>  	os.system("some command > outputFile.txt" )
>
> This redirects the output of "some command"'s stdout to "outputFile.txt". 
> However I need to redirect or somehow capture the output from "some 
> command"'s stderr to this file too. How can I do that?

You could do "some command >outputFile.txt 2>&1", or you could use the
commands.getoutput() or commands.getstatusoutput() methods.

Cheers,

-- 
Klaus Alexander Seistrup
Magnetic Ink, Copenhagen, Denmark
http://magnetic-ink.dk/



More information about the Python-list mailing list