In Perl, how to clone output to stdout and log file in real time
I want to clone the output to the console as well as the log file at the same time. Here is my code snippet:
open STDOUT, ">>", "temp.txt" or die "";
system("echo This is a sample output..........");
But here I am only getting output in temp.txt
, not on the console. Can you suggest a solution? I am using Windows.
+3
MRUDUL DOSHIT
source
to share
1 answer
It will be displayed on STDOUT
and temp.txt
,
use Capture::Tiny::Extended 'tee';
tee(
sub {
system("echo This is a sample output..........");
},
{ stdout => "temp.txt" }
);
+1
Dry27
source
to share