Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Catching STDERR

by mr.nick (Chaplain)
on Jun 27, 2001 at 04:36 UTC ( [id://91792]=note: print w/replies, xml ) Need Help??


in reply to Catching STDERR

Simple. Just open a file with the filehandle of STDERR:
#!/usr/bin/perl use strict; open(STDERR,">>error.log") || die "Couldn't redirect STDERR: $!\n"; print STDERR "This goes to the file.\n"; warn "As does this."; die "And this does, too!\n"; close STDERR;

Update: If you want to restore the original filehandle, then you'll have to do something like this:

open(OLDERR,">&STDERR") || die "Couldn't dup STDERR: $!\n"; open(STDERR,">>error.log") || die "Couldn't redirect STDERR: $!\n"; print STDERR "This goes to the file.\n"; warn "As does this."; open(STDERR,">&OLDERR") || die "Couldn't restore STDERR: $!\n"; warn "This goes to the screen.";
Btw, this is almost entirely taken from perldoc -f open.

mr.nick ...

Replies are listed 'Best First'.
Re: Re: Catching STDERR
by kiseok7 (Beadle) on Jun 27, 2001 at 04:46 UTC

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-03-29 04:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found