Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Capture Exit Code Using Pipe & Tee

by ambrus (Abbot)
on Jan 31, 2007 at 22:14 UTC ( [id://597647]=note: print w/replies, xml ) Need Help??


in reply to Capture Exit Code Using Pipe & Tee

If your shell is bash, check out the PIPESTATUS shell parameter. For example, $command = "make -f <parameters> 2>&1 | tee -a build.log; let \\!PIPESTATUS"; might work, but I haven't tested it.

Replies are listed 'Best First'.
Re^2: Capture Exit Code Using Pipe & Tee
by Anonymous Monk on Jan 31, 2007 at 23:10 UTC
    merlyn's answer was dead on, for some reason it earlier it wasn't returning an error code, now with a minor tweak to merlyn's code I was able to get it working exactly like I wanted. THANKS A MILLION! This is a best place on the net for anything perl. I will be donating some $$$....

    my code for completeness:

    open MAKE, "make -f <params> 2>&1 |" or die; open (LOGFILE, ">>build.log") or die; while (<MAKE>) { print LOGFILE $_; print } close MAKE; # to get $? my $exit = $? >> 8; close LOGFILE;

    Edit: g0n - code tags

      the code wasn't actually returning the error code for the make file as far as i could tell. I used it to run any program, and had to add this at the end:
      exit $exit;

        the code wasn't actually returning the error code for the make file as far as i could tell.

        Correct, because that wasn't the question. The question was about obtaining make's exit code.

Re^2: Capture Exit Code Using Pipe & Tee
by meonkeys (Chaplain) on Mar 05, 2009 at 22:57 UTC
    PIPESTATUS does indeed work when using Bash. Nice trick!
    false | tee /dev/null [ $PIPESTATUS -eq 0 ] || exit $PIPESTATUS

    ---
    "A Jedi uses the Force for knowledge and defense, never for attack."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://597647]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-25 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found