vatine: Generated with some CL code and a hand-designed blackletter font (Default)
vatine ([personal profile] vatine) wrote in [personal profile] jimx0r 2012-07-31 04:12 pm (UTC)

Do you want/need STDERR and STDOUT separated or in the same file?

If you're only after the latter, I think the following might do the trick (may be bash-only, may be POSICX-compliant, use with care, no warranties, etc, etc, so on and so forth):
exec 3>&1 # Save current stdout on fd 3
exec > /tmp/log 2>&1 # redirect stdout and stderr to the log file
tail -f /tmp/log >&3 &  # Start a tail
"$@"  # execute the passed-in command line
RV=$? # save exit status
kill %tail # kill the output
wait # wait for it to finish
exit $RV # and pass back the saved exit status


Simply pass in the script you want to log. If you want stdout and stderr archived separately, it gets a bit trickier. Also, you may want to use a sensible way of picking the log file.

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting