exit code of the first program in a pipe?

exit code of the first program in a pipe?

am 28.01.2008 17:27:02 von Mikhail Teterin

Hello!

I need to capture stdout of a program to a file, but still report it to
stdout too. I also need to react to a program's failure.

Unfortunately, the following construct:

if FOO | tee -a FOO.log
then
...
fi

Analyzes the exit-code of tee, rather than that of FOO. What's the correct
method? Thanks!

-mi

Re: exit code of the first program in a pipe?

am 28.01.2008 17:30:08 von Stephane CHAZELAS

On Mon, 28 Jan 2008 11:27:02 -0500, Mikhail Teterin wrote:
> Hello!
>
> I need to capture stdout of a program to a file, but still report it to
> stdout too. I also need to react to a program's failure.
>
> Unfortunately, the following construct:
>
> if FOO | tee -a FOO.log
> then
> ...
> fi
>
> Analyzes the exit-code of tee, rather than that of FOO. What's the correct
> method? Thanks!
[...]

That's a FAQ:

http://cfaj.freeshell.org/shell/cus-faq-2.html#11

--
Stephane

Re: exit code of the first program in a pipe?

am 28.01.2008 17:30:51 von Ed Morton

On 1/28/2008 10:27 AM, Mikhail Teterin wrote:
> Hello!
>
> I need to capture stdout of a program to a file, but still report it to
> stdout too. I also need to react to a program's failure.
>
> Unfortunately, the following construct:
>
> if FOO | tee -a FOO.log
> then
> ...
> fi
>
> Analyzes the exit-code of tee, rather than that of FOO. What's the correct
> method? Thanks!
>
> -mi

See question 11 in the FAQ:

http://cfaj.freeshell.org/shell/cus-faq-2.html#11

Ed.