Background of the question:
We have occasionally the problem, that on Windows a command
dutifully runs myProg.pl (as I can see from the files it creates), but no out.txt has been created (not even of length zero). This happens frequently enough to be annoying.system(1,'perl.exe','myProg.pl','>out.txt','2>&1')
I was not able to track down the bug (there is a long story behind it - let me know if you want to hear it -, but in short, the reason is not so simple as "someone erasing out.txt before I can look at it"). My best guess is that the redirection is either not set up at all in the failure cases, or by mistake done to the bit bucket.
Of course the "right" way to solve this is to find out *why* the redirection does not work from time to time, but this looks like a difficult task, and we need at least a temporary solution. One possibility would be to test STDOUT within myProg.pl. If it is attached to a file, great (and even greater if I could find out WHICH file it is attached to, but I guess this is too much to ask). If it is attached to NUL (the Windoze equivalent to /dev/null), or if it is not redirected at all, I could close STDOUT and redirect it to a new file. This would give me the output of the file, PLUS some diagnostics of what is going on.
UPDATE:Code example corrected.In reply to Test whether STDOUT is connected to a file by rovf
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |