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 want to write stdout to a file but also prints stdout and stderr. I tried using tee:

prog | tee stdout.txt

but this causes the printed stderr and stdout to be interleaved incorrectly, i.e. if the correct output should be

OUT1 ERR1
OUT2 ERR2
OUT3 ERR3
OUT4 ERR4

using tee might print them out of order, e.g.:

ERR1 ERR2
OUT1
OUT2 
OUT3 ERR3 
OUT4
ERR4

Is there any way to print both stdout and stderr to screen and also write the stdout to a file without gobbling up the printed output?

share|improve this question
1  
See Show only stderr on screen but write both stdout and stderr to file. There's no way unless you're willing to do some programming. –  Gilles May 19 '11 at 6:50

1 Answer 1

I would forward stdout to a file, then use tail to see the file content as it is written. That means you need to have two terminals open.

Terminal one:

prog > stdout.txt

Terminal two:

tail -f stdout.txt

So, in terminal two you will see stdout content as it is written to stdout.txt, and in terminal one you will see stderr. You can also forward both stdout and stderr to a file, and do the same thing. In that case you need to use prog >& outerr.txt. (This will work on tcsh, but you can do it in bash, too.)

share|improve this answer

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.