Capturing output from stderr

Discussion in 'Python' started by Doru-Catalin Togea, Dec 5, 2005.

  1. 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
     
    Doru-Catalin Togea, Dec 5, 2005
    #1
    1. Advertising

  2. 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/
     
    Klaus Alexander Seistrup, Dec 5, 2005
    #2
    1. Advertising

  3. 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. >>
    <<<< ================================== >>>>
     
    Doru-Catalin Togea, Dec 5, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fuzzyman
    Replies:
    3
    Views:
    652
    Gabriel Genellina
    Jan 7, 2007
  2. Carl Lerche

    Capturing stderr from Kernel.exec

    Carl Lerche, Sep 9, 2006, in forum: Ruby
    Replies:
    2
    Views:
    134
  3. Ted Flethuseo

    capturing stderr for a file

    Ted Flethuseo, Feb 17, 2011, in forum: Ruby
    Replies:
    1
    Views:
    114
    Avdi Grimm
    Feb 17, 2011
  4. Brian

    capturing stderr from windows

    Brian, Apr 19, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    92
    Toni Erdmann
    Apr 22, 2004
  5. Mike

    capturing stdout and stderr?

    Mike, Aug 9, 2009, in forum: Perl Misc
    Replies:
    0
    Views:
    104
Loading...

Share This Page