in reply to Re: Testing whether a file handle is attached to STDOUT
in thread Testing whether a file handle is attached to STDOUT

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>

Replies are listed 'Best First'.
Re^3: Testing whether a file handle is attached to STDOUT
by Corion (Patriarch) on Jun 16, 2011 at 10:55 UTC

    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.

Re^3: Testing whether a file handle is attached to STDOUT
by BrowserUk (Patriarch) on Jun 16, 2011 at 10:56 UTC
    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.