Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I would like to direct:

  • Standard out 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 out on the console where I only want to see errors.

Any help would be appreciated.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This is not optimal but it should do:

exec 3>mylogfile; mycmd 2>&1 >&3 | tee >(tee >&3);exec 3>&-;

have fun playing with this.

share|improve this answer
    
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 '11 at 0:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.