Shell redirection of stderr and stdout doesn't synchronize.
Thursday, November 3, 2011 12:52:12 PM
The common advice is to use
program >& output.txt
The advanced advice is to use
program > output.txt 2>&1
But at times, both fail. On my machine stderr is written before stdout. Sometimes all stderr is at the beginning of output.txt sometimes there are even lines of stderr written in the middle of a line of stdout. Where it is written is partly luck, it seems constant on the same machine but different on another.
Piping the output through more brings another result, but not the desired one:
these variants seem to behave equivalent:
program |& more > test.log program 2>&1 | more > test.log program 2>&1 | > test.log
Turning buffering off altogether is no option, because it would slow down the program too much.
So, if someone has another idea, please tell.

