in reply to Check system return codes

Since you are using the system command to execute these programs then the pipe is managed by a shell, so to get the return code (other than the last one) you need a shell solution.

If you use Bash then you can access the pipe return code using the array PIPESTATUS, recent Korn shell version support one called 'pipefail'.

You would probably be better managing the pipe yourself in Perl through open, and you will find that you don't need tee(1).

Replies are listed 'Best First'.
Re^2: Check system return codes
by eyepopslikeamosquito (Archbishop) on Jun 24, 2008 at 10:13 UTC

    If you use Bash then you can access the pipe return code using the array PIPESTATUS, recent Korn shell version support one called 'pipefail'
    With enough /bin/sh file descriptor fu, this can even be done using an ancient Bourne shell, as demonstrated by Tom Christiansen in a famous 1996 post, Csh Programming Considered Harmful. For example:
    exec 3>&1 rc=`(($SOME_COMMAND 2>&1 3>&- 4>&-;echo $? 1>&4) | tee -a $LogFile 1>& +3 3>&- 4>&-) 4>&1` exec 3>&- # $rc has the return code of $SOME_COMMAND.