How can I redirect the output of a command such that both stdout and stderr gets logged in a file, AND I still want stderr to appear as output.
I also don't want to use bash for doing this. Is there such a way?
How can I redirect the output of a command such that both stdout and stderr gets logged in a file, AND I still want stderr to appear as output.
I also don't want to use bash for doing this. Is there such a way?
That is very easy:
$ ( ./command.sh >> log ) 2>&1 | tee -a log
You write the stdout of command to the log
file in a sub shell; than you write
stderr to pipe; and than, my means of tee
, save it to the log
and copy the same to the console.
Example of usage:
$ cat command.sh
#!/bin/sh
echo out
echo err > /dev/stderr
$ ( ./command.sh >> log ) 2>&1 | tee -a log
err
$ cat log
out
err