If the command runs quickly:
If it is a long-running command and you want feedback while it is running:my $out = `cmd-to-run 2>&1`; # Should really check command return code via $? special variable here # Then print $out via your $tee here # Note: 2>&1 (to fold stderr into stdout) works fine on Windows XP
And autoflushing stdout ($| = 1;) is prudent in these type of scripts to avoid any intermingling of command stdout and your script's stdout.open(my $fh, 'cmd-to-run 2>&1 |') or die "open error: $!"; while (<$fh>) { # print $_ via your $tee here } close($fh) or die "close error: $!";
In reply to Re: How do I redirect outut from system () to a file and also to screen
by eyepopslikeamosquito
in thread How do I redirect outut from system () to a file and also to screen
by gim
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |