in reply to Re: How do I redirect outut from system () to a file and also to screen
in thread How do I redirect outut from system () to a file and also to screen

Brian,

The backticks work fine!! Thanks for your help.

use IO::Tee;
my $tee = IO::Tee -> new(">stdout.log", \*STDOUT);

my $clrout = `cleartool describe lbtype:MYLABEL`;
print $tee "\n$clrout also prints to screen and redirects to file!\n";
print $tee "\nThis will print to screen and redirects to file!\n";

  • Comment on Re^2: How do I redirect outut from system () to a file and also to screen

Replies are listed 'Best First'.
Re^3: How do I redirect outut from system () to a file and also to screen
by ivancho (Hermit) on May 25, 2005 at 01:23 UTC
    You won't tee your STDERR with backticks, though. All they do is point the command's STDOUT to a string, which is then given back to you. STDERR still goes to the original STDERR, unless you do  `command 2>&1`, which will include the error messages too.

    This seems to work even under Win, even though it's bash syntax.
    Update: as eyepopslikeamosquito already points out below

    This, of course, shoves everything in the same log, which is not optimal - Log::Log4perl is probably your best friend here, and it will do you a ton of good in the future too, once you learn its ways