3

I want to clone the output to the console as well as to a log file simultaneously. Here is my code snippet:

open STDOUT, ">>", "temp.txt" or die "";
system("echo This is a sample output..........");

But, here I only get output in the temp.txt and not on the console. Can you suggest a solution? I am using Windows.

dgw
  • 13,418
  • 11
  • 56
  • 54

1 Answers1

1

It will output to STDOUT and temp.txt,

use Capture::Tiny::Extended 'tee';

tee(
  sub { 
    system("echo This is a sample output..........");
  },
  { stdout => "temp.txt" }
);
mpapec
  • 50,217
  • 8
  • 67
  • 127