Chris wrote:

> I need to log stdout and stderr from a sub of a perl module. I am
> unable to make use of modules such as open3. Any ideas?
> 
> myscript.pl
> 
> $myobj = new ($pm);
> $myobj->doprint(); #need to capture stderr, stdout from $myobj
> 
> mymodule.pm
> 
> sub doprint {
> print 'hello world';
> die 'goodbye cruel world';
> }

dup the file handles to the log files you want:

#!/usr/bin/perl -w
use strict;

open(STDOUT_LOG,">stdout.log") || die $!;
open(STDERR_LOG,">stderr.log") || die $!;

open(STDOUT,">&STDOUT_LOG") || die $!;
open(STDERR,">&STDERR_LOG") || die $!;

print "hello world\n"; #-- goes to the file stdout.log
warn "hi world\n" #-- goes to the file stderr.log

__END__

to trap die:

$SIG{__DIE__} = sub {print "whatever\n"; };

when you dup the file handles, it makes sense to save the old ones first so 
later you can revert it back.

check out perldoc -f open for more help. HTH

david

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to