Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Building a log file

by moritz (Cardinal)
on Jun 23, 2009 at 14:52 UTC ( [id://774046]=note: print w/replies, xml ) Need Help??


in reply to Building a log file

Sure, perl $yourscript.pl | tee logfile.

You can also duplicate the STDOUT file handle as described in perlopentut or open.

Replies are listed 'Best First'.
Re^2: Building a log file
by Marshall (Canon) on Jun 23, 2009 at 15:20 UTC
    This is a good idea. Windows systems don't have tee, I hacked in this tee.pl awhile ago for my Windoze work. It is a simple program. The only tricky part is turning auto-flush on for write. Have fun to anybody who needs it.
    #!/usr/bin/perl -w use strict; # tee program #### tee.pl ###### # quickie tool $| =1; #flushes I/O for each write. sub usage { print "TEE USAGE:\n tees stdout to a file and to stdout\n". " program | tee outfile\n"; } my $filename = shift @ARGV; usage unless $filename; open (OUTFILE, '>', "$filename") or (die "Can't open OUTFILE: $!"); while (<>) { print; print OUTFILE; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://774046]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-05-21 01:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found