in reply to output of multiple processes
From your code it looks like:
If so, you can use the tee command, but it requires juggling some file handles:
Alternatively, in the Perl Cookbook, there is an example of how to implement tee within perl by using tied file handles. Look for the Tie::Tee example at the end of Chapter 13.sub Pooled_function { open(my $STDOUT_SAVE, ">&STDOUT"); # save current STDOUT while (<$parentfh>) { chomp; my ($pclass, $copy_to_console) = split(' ', $_, 2); my $file = ...; if ($copy_to_console) { open(STDOUT, ">&", $STDOUT_SAVE); open(OUT, "|-", "tee", $file); } else { open(OUT, ">", $file); } open(STDOUT, ">&OUT"); open(STDERR, ">&OUT"); # Do the stuff close(STDOUT); close(STDERR); close(OUT); } close($parentfh); }
|
|---|