P:\test>perl -e"print 'This goes to stdout', $/; print STDERR 'This go
+es to STDERR', $/;" 1>junk.log 2>&1
P:\test>type junk.log
This goes to STDERR
This goes to stdout
One caveat is that in common with several other POSIX systems, you need to do this in the right order; that shown above. The other way around does not do the same thing.
The other caveat, also common to many systems, is that depending upon the buffering stratecies used internally by the program you are running, you may find that the output from the two streams is not correctly interleaved. Often this shows up as STDERR output showing up before STDOUT lines, with the latter tending to come bunched together in blocks. This is because STDOUT os often buffered whereas STDERR is not. You'll notice in the above example the STDERR line precedes the STDOUT line.
If the programs/commands in question are other perl scripts then you can correct this by disabling buffering on STDOUT, but if they are programs written in C (or other languages) to which you do not have the source, there is little or nothing you can do about this.
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
|