MRUDUL DOSHIT
MRUDUL DOSHIT

Reputation: 63

In Perl, how to clone output to stdout and a log file in real time

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.

Upvotes: 3

Views: 91

Answers (1)

mpapec
mpapec

Reputation: 50667

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" }
);

Upvotes: 1

Related Questions