in reply to Re: trying to copy STDERR STDOUT on win32
in thread trying to copy STDERR STDOUT on win32

Tie::FileHandle::MultiPlex looks promising but I don't see how this can send my STDOUT to a file and STDOUT at the same time. I was able to send all STDERR and STDOUT to a file but was unable to also have it display it ti STDOUT. In a nutshell I want to capture all errors and output to a log as well as display it to the user. Were you able to accomplish this with Tie::FileHandle::MultiPlex? If so would I be out of line by asking you for some sample code?
  • Comment on Re^2: trying to copy STDERR STDOUT on win32

Replies are listed 'Best First'.
Re^3: trying to copy STDERR STDOUT on win32
by DrWhy (Chaplain) on Aug 18, 2005 at 15:31 UTC
    You have to dup STDOUT and then tie STDOUT with Tie::F::M, giving the dup of STDOUT as one of the 'real' handles to write to. Here's an example:
    open F, '>outfile.txt' or die "opening output file: $!\n"; open DUPOUT, '>&STDOUT' or die "Can't dup stdout: $!\n"; tie *STDOUT, 'Tie::FileHandle::MultiPlex', *DUPOUT, *F;

    --DrWhy

    "If God had meant for us to think for ourselves he would have given us brains. Oh, wait..."

      Ahhhh, I see. Thanks so much, this is exactly what I wanted to do.