in reply to trying to copy STDERR STDOUT on win32

I'm not sure this is what you want, but this code will cause die message to got to STDERR and ERRFILE, but warnings will go to STDOUT and ERRFILE.

All-in-all, You might want to look at IO::Tee and/or Tie::FileHandle::MultiPlex to accomplish this more cleanly.

I accomplished a similar thing with Tie::FileHandle::MultiPlex and it worked well for me.

--DrWhy

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

  • Comment on Re: trying to copy STDERR STDOUT on win32

Replies are listed 'Best First'.
Re^2: trying to copy STDERR STDOUT on win32
by boat73 (Scribe) on Aug 18, 2005 at 12:55 UTC
    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?
      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.