How can I directly output from the program to the console and the log file?

How can I print the output to the terminal and the file at the same time?

$ perl foo.pl > foout.txt

doesn't let me see a living process.

Is there a way to see the output process in real time and get the screen output to a file at the end?

+3
source share
4 answers

perl foo.pl | tee foout.txt

+17
source

The tee utility will do this.

+9
source

. IO::Tee. ( , File::Tee, , - ).

. Log4perl , .

, , , , tee, .

+7

perl ( , Unix tee)

perl foo.pl | perl myPipe.pl myFile.txt

myFile.txt

myPipe.pl

#
open OUTFILE,">$ARGV[0]" or die "Unable to open file: $ARGV[0]\n";

while(<>)
{
    print;
    print OUTFILE;
}
close OUTFILE;

STDIN , . ,

0

Source: https://habr.com/ru/post/1713576/


All Articles