in reply to Testing whether a file handle is attached to STDOUT

You'd probably be better off checking that fileno( $fh ) == 1.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^2: Testing whether a file handle is attached to STDOUT
by rovf (Priest) on Jun 16, 2011 at 10:51 UTC

    But is *that* portable? It would certainly work on Unix, but how about the Windows family? In particular, Windows 2000, NT and 7 - can we rely on fileno(*STDOUT) always being 1?

    -- 
    Ronald Fischer <ynnor@mm.st>

      Yes, the file numbers for STDIN / STDOUT and STDERR behave the same also on Windows. unistd.h defines them to be 0, 1 and 2 respectively.

      Beware though that if you close one of the three, the file numbers may be reallocated to other filehandles.

      In particular, Windows 2000, NT and 7 - can we rely on fileno(*STDOUT) always being 1?

      Yes. It is a standard C thing, not OS dependant.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.