in reply to Teeing STDOUT and STDERR to files using filehandle references

Okay, lemme clarify a bit... the part I can't figure out how to do is redirecting STDOUT to $FH_STATUS.

--isotope
http://www.skylab.org/~isotope/
  • Comment on Re: Teeing STDOUT and STDERR to files using filehandle references

Replies are listed 'Best First'.
Re: Re: Teeing STDOUT and STDERR to files using filehandle references
by repson (Chaplain) on Dec 16, 2000 at 07:30 UTC
    How about dupping the filehandle:
    sub open_logfile { my $filename = shift; open STDOUTBACK, '>&STDOUT' or die "Can't dup STDOUT\n"; open STDOUT, '> ' . $filename or die "can't write to $filename: $!\n +"; }
    In this case any attempt to print "foo\n" or print STDOUT "foo\n" will go to the logfile.

    Or just use select:

    sub open_logfile { my $filename = shift; open FH, '> ' . $filename or die "Can't write to $filename: $!\n"; select FH; }
    In the second case print "foo\n" will print where you want but print STDOUT "foo\n" will still go to the real STDOUT.
      This is correct, but it's not the solution to my problem... I'm redirecting to existing filehandles, not opening new files.

      --isotope
      http://www.skylab.org/~isotope/
Re: Re: Teeing STDOUT and STDERR to files using filehandle references
by cwest (Friar) on Dec 16, 2000 at 01:22 UTC
    check perltie for tying file handles... there's also IO::Handle for that task.
    --
    Casey
       I am a superhero.