Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Catching STDERR

by RhetTbull (Curate)
on Jun 27, 2001 at 07:12 UTC ( #91825=note: print w/ replies, xml ) Need Help??


in reply to Catching STDERR

The aforementioned methods will work great if you want to redirect STDERR to a file. However, if you want to redirect it to a file AND still display it on the STDERR device (e.g. the screen) you might try Filter::Handle. It will let you attach a sub to a file handle (including STDERR) so that you can print the output to a file or filter it any way you like in addition to printing to the terminal. Here's a little snippet to get you started.

use warnings; use strict; use Filter::Handle qw/subs/; open (LOGFILE, ">logfile") || die "could not open logfile"; #filter STDERR through an anonymous sub Filter \*STDERR, sub {local $_ = "@_"; print LOGFILE "Filtered: $_ "; +$_}; #prints to both STDERR and to LOGFILE print STDERR "error!\n"; #STDERR will no longer be filtered through your sub UnFilter \*STDERR; close LOGFILE;
Regards,
Rhet


Comment on Re: Catching STDERR
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (9)
As of 2014-12-26 22:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (176 votes), past polls