Problems? Is your data what you think it is? | |
PerlMonks |
ordering of stdout and stderr outputsby Special_K (Monk) |
on Dec 22, 2014 at 17:35 UTC ( [id://1111052]=perlquestion: print w/replies, xml ) | Need Help?? |
Special_K has asked for the wisdom of the Perl Monks concerning the following question: I am trying to figure out how perl determines the order in which to output STDOUT and STDERR text, both to a terminal and to a file. Consider the following code:
If I run this code in a terminal, the output is as follows:
As you can see, the stdout text is interleaved with the stderr, which is what I would expect based on the order of the printf statements. If I redirect the text to a file however, the result is different:
where log contains:
As you can see, in this case perl first outputs all the stderr output, then outputs all the stdout output. Why does it do this? Why is the behavior different when I output to a file vs. the terminal? More importantly, how can I force the file output to appear in the correct order? Debugging is much easier when printed statements appear in programatic order. I tried adding the following to my code above:
but that didn't make any difference in my output file.
Back to
Seekers of Perl Wisdom
|
|