Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

stdout/err redirection

by Anonymous Monk
on Jul 10, 2002 at 21:23 UTC ( [id://180876]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, i use a logging package which i inherited from a previous programmer. it redirects STDOUT to both the log file and the console, and STDERR to only the log file.
open LOG, ">> $logfile"; open STDERR, ">&LOG"; select LOG; $| = 1; select STDERR; $| = 1; select STDOUT;
i'd like to redirect both STDOUT and STDERR to the log file and console, but i'm having trouble doing so. can someone help?

Replies are listed 'Best First'.
Re: stdout/err redirection
by DamnDirtyApe (Curate) on Jul 10, 2002 at 21:37 UTC

    There may well be a more elegant way to do this than mine, but if your using Unix/Linux, you may have some success with the tee command. Something along these lines:

    #! /usr/bin/perl use strict ; use warnings ; $|++ ; my $logfile = 'my_log.txt' ; open STDOUT, "| tee $logfile" ; open STDERR, ">&STDOUT" ; print STDOUT "I'm going to standard output.\n" ; print STDERR "I'm going to standard error.\n" ;

    Both messages go to the console, and to the log file.


    _______________
    D a m n D i r t y A p e
    Home Node | Email
Re: stdout/err redirection
by stefp (Vicar) on Jul 11, 2002 at 00:26 UTC
    This is not a perl solution, but if you need redirection for the lifetime of a process. socat is a sure bet. NTK said: : . If Perl is the Swiss Army chainsaw of programming languages, then SOCAT is the Swiss Army chainsaw of, uh, shell/networking tools. BTW, NTK tracking section is a must read every friday evening.

    socat is way better than netcat.

    -- stefp -- check out TeXmacs wiki

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (2)
As of 2024-04-24 23:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found