1

I would like to direct:

  • Standard output to file.
  • Standard error to the same file.
  • Standard error to console (as well as file).

I've seen this kind of thing:

mycommand 2>&1 | tee test.txt

But it shows standard output on the console where I only want to see errors.

1 Answer 1

1

This is not optimal, but it should do:

exec 3>mylogfile; mycmd 2>&1 >&3 | tee >(tee >&3);exec 3>&-;
1
  • Thanks for this. Seems to work ok on most of our scripts. Have got one script which I'm running with this, which just hangs until I Ctrl-C it. It finishes straight away without the "tee >(tee >&3)" bit, but hangs around when that bit is there. Will debug it a bit more.
    – Ben
    Apr 6, 2011 at 0:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .