This is a follow-up to this question:
How do I get both STDOUT and STDERR to go to the terminal and a log file?
In short: I want to run a command and store both, STDOUT
and STDERR
in one log file (to keep time correlation) but I need STDERR
output still to be printed on STDERR
.
Motivation: there are tools which run a command and treat STDOUT
and STDERR
differently - e.g. printing STDERR
in a different color or print STDERR
when the command returns non-zero.
So I'd like to have a way to store all output in one log file but preserve the distinction between STDOUT
and STDERR
(as well as the return code).
log-output --file=command.log -c "make stuff-with-stderr"
From what I found in the above links answers there are at least two different approaches:
the_cmd 1> >(tee stdout.txt ) 2> >(tee stderr.txt >&2 )
will store STDOUT
and STDERR
in separate files, thus loosing time correlation. And unfortunately both STDOUT
and STDERR
will be printed on STDOUT
only.
script -e -B build.log -c "the_cmd"
will store both STDOUT
and STDERR
in one file, keeping time correlation but still prints both STDOUT
and STDERR
on on STDOUT
only.
So none of those approaches meets my requirements. Is there something else?