Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Capturing output from stderr

Reply
Thread Tools

Capturing output from stderr

 
 
Doru-Catalin Togea
Guest
Posts: n/a
 
      12-05-2005
Hi!

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?

Thanks,
Catalin


 
Reply With Quote
 
 
 
 
Klaus Alexander Seistrup
Guest
Posts: n/a
 
      12-05-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/
 
Reply With Quote
 
 
 
 
Doru-Catalin Togea
Guest
Posts: n/a
 
      12-05-2005
On Mon, 5 Dec 2005, Doru-Catalin Togea wrote:

Found a solution:

os.system("some command 1>out.txt 2>err.txt")

> 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?
>
> Thanks,
> Catalin
>
>
>


--

<<<< ================================== >>>>
<< We are what we repeatedly do. >>
<< Excellence, therefore, is not an act >>
<< but a habit. >>
<<<< ================================== >>>>
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
capturing stderr for a file Ted Flethuseo Ruby 1 02-17-2011 02:09 AM
capturing stdout and stderr? Mike Perl Misc 0 08-09-2009 09:33 PM
Capturing stderr and stdout of a subprocess as a single stream Fuzzyman Python 3 01-07-2007 08:44 PM
Capturing stderr from Kernel.exec Carl Lerche Ruby 2 09-09-2006 04:01 AM
capturing stderr from windows Brian Perl Misc 4 04-22-2004 07:11 AM



Advertisments