[ILUG] Logging and displaying output of shell commands
Darragh Bailey
felix at compsoc.nuigalway.ie
Tue Oct 7 12:03:38 IST 2008
Have a build system comprised of make files, where I have one macro that
tries to capture the output of commands and stores it in a log file as
well as displaying it to the user should a variable be set.
Basically, the idea is that when calling make, users will just use the
following form:
$ make rulename
which will only output messages at various points (some rules will use
echo at the start to inform the user of where they currently are).
At the same time the output from all the commands run by the make rules
is outputted into log files, so that they can be viewed if there is a
problem.
Now I also wanted to permit a user to set a variable on the command line
(V), to also output to the stdout everything that is going to the log
files.
make macro
log = $(if $(filter 2,$(V)),2>&1 | tee -a $1,>> $1 2>&1)
Problem occurs that if V=2, tee is used which results in the wrong exit
code being received by the make rule.
i.e.
rule:
somerule:
@some_command $(call log,mylog.log)
With V=1, this becomes:
somerule:
@some_command >> mylog.log 2>&1
With V=2, this becomes:
somerule:
@some_command 2>&1 | tee -a mylog.log
Problem is that when there is an error executing some_command and V=2,
then make only receives the exit code of tee, which barring some problem
in tee itself is always going to be 0.
Any suggestions on how to get the output to go to the log file in all
three cases while still resulting in the correct exit code being given
to make?
--
Darragh
"Nothing is foolproof to a sufficiently talented fool."
More information about the ILUG
mailing list