What $| =1; does is un-buffer STDOUT. STDERR is already un-buffered by default.
What buffering does is to gather up stuff until it reaches a "quanta" of stuff to write. Then the O/S writes it all at once. This difference matters a lot in terms of performance. For writing to a HD, maybe 4Kbytes or 8Kbytes might be the "quanta" for stdout.
When $|=1 is in effect, each print statement will actually access the HD for every print.
Note that you can redirect stdout and stderr individually from the command line. The default is only re-direct stdout, "someprog >stdoutfile"."command > combinedfile 2>&1" re-directs both std-err and std-out to the same file.
For some programs that run for a long time on the command line, I use stderr to print status, "working on X..". I do that so that I can see that the program is not "hung". And I send any actual error to both stderr and stdout.
I think that all you need to do is set: $|=1; When you do that, the "errors" and the "output" will occur together on the stdout console. When you have the program working, then take $|=1; out if you want it to run faster. $|=1 eliminates the delay between an error and the next stdout line, also stdout lines appear in "real time" instead of there being a delay. It is certainly possible that if the "buffering write quanta" is not fulfilled, that the program doesn't print anything until it actually has already exited!
In reply to Re^2: How to print called program to stdout
by Marshall
in thread How to print called program to stdout
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |