I'm not 100% sure this will work on windows since I can't test, but it should be OK.use IPC::Run qw/run/; use IO::Tee; my $tee = IO::Tee->new(">output.log", \*STDOUT); # called output.log b +ecause it's both stderr and stdout my $printer = sub { print $tee @_ }; # kludge because IO::Tee doesn't +implement the FILENO method my $in = ""; # this data is sent into the command run [qw/cleartool describe lbtype:MYLABEL/], \$in, $printer, $printer;
IPC::Run will call the anonymous sub in $printer every time there's output on STDOUT or STDERR. That's why it's passed twice. This sub just delegates to tee, which will write the output on STDOUT and the file, like you did before.
Ideally it would look like
But I think IPC::Run's parameter processing does not recognize $tee as a file handle, since fileno($tee) breaks.run [qw/cleartool describe lbtype:MYLABEL/], \$in, $tee, $tee;
You can also ask IPC::Run to dup STDERR to STDOUT, by doing something like this (untested):
Which is more concise, but doesn't show how flexible IPC::Run is ;-)run [qw/cleartool describe lbtype:MYLABEL/], ">&", $printer;
In reply to Re: How do I redirect outut from system () to a file and also to screen
by nothingmuch
in thread How do I redirect outut from system () to a file and also to screen
by gim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |