I need to route the output of a command to both the terminal and a file,
but I still need access to the command status (because this is being
done in a makefile).
Suppose the command is blotz, then the make rule
A : B
blotz -o A B
will run the blotz command on file B and produce file A. The messages
from blotz are sent to the terminal, and make properly stops if blotz
returns a non-zero exit status.
Now to log the output to a file I try this:
A : B
blotz -o A B | tee make_output
The blotz messages now go to the terminal and into the make_output file,
but make gets the exit status of the tee command instead of the blotz
command. Make can't tell when the blotz command fails.
I can just redirect the blotz output
A : B
blotz -o A B > make_output
but the blotz command takes a long time and prints progress messages
which I would like displayed as well as logged.
Is there a way to get the exit status from the first element of a
command pipeline? Or is there some other way to get the messages into a
file and onto the terminal without piping the result through tee?