How can I capture STDERR and get an exit code?

Discussion in 'Perl Misc' started by Jake Cahoon, Jun 10, 2004.

  1. Jake Cahoon

    Jake Cahoon Guest

    I need to run a system command, find out if it failed and put its
    output in a log file. The way I am trying to do it right now is to
    get the exit code from the command with system() but then I don't know
    how to capture its output. The backticks are the opposite problem. I
    can capture the command's output but I don't know what its exit code
    is. It just seems like an ugly solution to me to have to pattern
    match the command's output just to see if the command executed
    successfully.

    Anyone have some tips?

    Thanks,

    J Cahoon
     
    Jake Cahoon, Jun 10, 2004
    #1
    1. Advertising

  2. Jake Cahoon

    Paul Lalli Guest

    On Thu, 10 Jun 2004, Jake Cahoon wrote:

    > I need to run a system command, find out if it failed and put its
    > output in a log file. The way I am trying to do it right now is to
    > get the exit code from the command with system() but then I don't know
    > how to capture its output. The backticks are the opposite problem. I
    > can capture the command's output but I don't know what its exit code
    > is. It just seems like an ugly solution to me to have to pattern
    > match the command's output just to see if the command executed
    > successfully.
    >
    > Anyone have some tips?


    Read perldoc perlvar. Look for the section on the $? variable. Read it
    thoroughly. It might not be *quite* what you expect.

    Paul Lalli
     
    Paul Lalli, Jun 10, 2004
    #2
    1. Advertising

  3. Jake Cahoon

    Paul Lalli Guest

    On Thu, 10 Jun 2004, Paul Lalli wrote:

    > On Thu, 10 Jun 2004, Jake Cahoon wrote:
    >
    > > I need to run a system command, find out if it failed and put its
    > > output in a log file. The way I am trying to do it right now is to
    > > get the exit code from the command with system() but then I don't know
    > > how to capture its output. The backticks are the opposite problem. I
    > > can capture the command's output but I don't know what its exit code
    > > is. It just seems like an ugly solution to me to have to pattern
    > > match the command's output just to see if the command executed
    > > successfully.
    > >
    > > Anyone have some tips?

    >
    > Read perldoc perlvar. Look for the section on the $? variable. Read it
    > thoroughly. It might not be *quite* what you expect.
    >
    > Paul Lalli


    Re-reading your post, you might be better off or at least aided by reading
    the FAQ on this topic:

    perldoc -q STDERR
    "How can I capture STDERR from an external command?"


    Paul Lalli
     
    Paul Lalli, Jun 10, 2004
    #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. =?Utf-8?B?U2FuZHk=?=

    Code to Exit Web App and Exit Internet Explorer

    =?Utf-8?B?U2FuZHk=?=, Aug 3, 2005, in forum: ASP .Net
    Replies:
    7
    Views:
    7,913
    =?Utf-8?B?U2FuZHk=?=
    Aug 5, 2005
  2. GinTon

    sys.stderr.write and sys.exit

    GinTon, Nov 23, 2006, in forum: Python
    Replies:
    5
    Views:
    582
    Dennis Lee Bieber
    Nov 24, 2006
  3. Yujo
    Replies:
    2
    Views:
    411
    Gabriel Genellina
    Apr 10, 2007
  4. chad
    Replies:
    14
    Views:
    585
    Arnaud Delobelle
    Oct 13, 2010
  5. PerlFAQ Server
    Replies:
    0
    Views:
    301
    PerlFAQ Server
    Mar 12, 2011
Loading...

Share This Page