in reply to Test if STDOUT is attached to console or shell redirected filehandle

But if Perl is oblivious to whats happening to STDOUT I'll devise another workaround

Perl is not oblivious to this, you would notice the difference when you note these characteristics:

  1. When STDOUT is attached to the terminal it'd have a line-buffered-mechanism, so such a filehandle would be flushed automatically when printing a newline character to it, or whenever you read from the terminal.
  2. When STDOUT is attached to an output file this flushing doesn't take place the same way above, and the program would not write to a file until after it's run throughout or after the buffer has been filled and needed purging (flushing).
  3. STDERR is always in line-buffered mode.

I found this useful link just today, I learnt a lot from it, take a look at it :).


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.
  • Comment on Re: Test if STDOUT is attached to console or shell redirected filehandle
  • Download Code

Replies are listed 'Best First'.
Re^2: Test if STDOUT is attached to console or shell redirected filehandle
by desemondo (Hermit) on Sep 07, 2009 at 02:26 UTC
    Indeed, when you put it like that - its obvious that Perl is aware. Kudos!