in reply to Re^3: Problems with Filehandles and TeeOutput
in thread Problems with Filehandles and TeeOutput

Thanks, IO::Tee gets me a little bit closer
#!/usr/bin/perl -w use strict; use warnings; use IO::Tee; use IO::File; my $stdout; open(my $fh, "+<", \$stdout); my $tee = new IO::Tee(\*STDOUT, $fh); print $tee `echo Test`; print $stdout;
However I am actually trying to capture STDERR, so this code isn't that useful to me. I have tried IO::CaptureOutput but I can't get that working. Note apologies, as I know that this (capturing STDERR to local variable as well as directing to file) has been covered many times before perlmonks and elsewhere, but I haven't come across a definitive solution - I was hoping that TeeOutput would be the answer, I guess not.

Replies are listed 'Best First'.
Re^5: Problems with Filehandles and TeeOutput
by ikegami (Patriarch) on Aug 26, 2008 at 18:08 UTC

    However I am actually trying to capture STDERR, so this code isn't that useful to me.

    You can't pass the file handles created by Tee modules to child processes since they don't correspond to system file handles, and neither is the file handle returned by open \$var.

    You should probably start a new thread and state your actual problem. I could try to come up with an answer, but you'd benefit from starting over because 1) the question hasn't fully been revealed, and 2) you'd get more answers than just my own.