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