I'm trying to merge a Perl script's STDOUT and STDERR streams, and fork it off to a log file.
open( MERGED, "|-", "tee /tmp/my.log" );
*STDOUT = *MERGED;
*STDERR = *MERGED;
print "1: print\n";
warn "2: warn\n";
system "echo 3: system call";
In this example, the "print" and "warn" messages appear in both the terminal and the log, while the system call appears only in the terminal.
How can I split my output streams off to a log file?
Note: only needs to work in Unix, and I don't want rely on packages that aren't part of the standard Perl distribution (e.g. File::Tee, IO::Tee..).
print qx(echo 3: backtiks)- mpapecopen(my $sub, "-|", "echo 3" ); print while <$sub>- mpapec