in reply to Re: Test whether STDOUT is connected to a file
in thread Test whether STDOUT is connected to a file

Why not simply pass the filename of the file-to-be-written to the program, and let it do the file writing in any case?
Because if I do this, I don't get any diagnostics about the error case. Note that I still *guess* what's going on, so for example the information "STDOUT in the error case is still connected to the same stream as in the parent" would be helpful.
On Linux, the -p file test can tell you if STDOUT is connected to a pipe, no idea if that works on windows too (Update: -t is probably more informative than -p).
There is an entry in perlfaq8 about this, which is not very encouraging:

How do I find out if I'm running interactively or not? Good question. Sometimes "-t STDIN" and "-t STDOUT" can give clues, sometimes not. if (-t STDIN && -t STDOUT) { print "Now what? "; }

-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^3: Test whether STDOUT is connected to a file
by wazoox (Prior) on Aug 19, 2010 at 10:46 UTC
    Because if I do this, I don't get any diagnostics about the error case.

    You could redirect the STDERR to STDOUT in the called perl program, then you wouldn't need to rely upon a broken bourne-shell emulation under windows.