Capture Exit Code Using Pipe & Tee



I have a piece of code provided below. The code calls a make command,
and redirects STDOUT/STDERR to tee, which then sends it to the screen,
and also to a log file. The problem is that I'm trying to capture the
exit code for make. However, what happens when I run the command a cmd
process starts up, and calls make and tee as peers, so make exits
first, then tee, which returns the exit code of tee to cmd, and cmd
returns the exit code to the script. What I need is the exit code from
make, and not tee.


$command = "make -f <parameters>";
$command .= " 2>&1 | tee -a build.log";
system $command;
$exit_value = $? >> 8;
print "\nExit Value: $exit_value\n\n";


The exit value is always 0, because it's returning the tee value, and
not make.


Any and all help is very appreciated.

.



Relevant Pages

  • Re: system(), pipe and exit codes
    ... zero exit code, retcode is always zero because of the pipe to 'tee'. ... There seem to be a solution to capture the exit codes of all the ... effectively doing the "tee" in your code. ... pcloseon the first stream will give you the exit status of the gmake command. ...
    (comp.unix.programmer)
  • Re: Capture Exit Code Using Pipe & Tee
    ... and redirects STDOUT/STDERR to tee, which then sends it to the screen, ... first, then tee, which returns the exit code of tee to cmd, and cmd ... generates five lines to STDERR and five to STDOUT. ... Warning 1 ...
    (perl.beginners)
  • how to capture return code
    ... how do I capture the return code of a command the output of which I pipe ... into tee? ... not from cmd. ...
    (comp.unix.shell)
  • Re: redirect to a file and monitor at once
    ... such as monitor in command window. ... I have found that DOS ports of TEE seem to not support STDERR ... Or Search within help centre for "Using command redirection operators" ...
    (comp.os.msdos.programmer)
  • Re: Howto parse stdout without changing it
    ... > I would like to parse stdout from a command list but also piped stdout to ... I guess you are looking for `tee`. ... echo "gzip result: $" ...
    (comp.unix.shell)