absolut.todd has asked for the wisdom of the Perl Monks concerning the following question:
I am using this module that I have written:
And early in the program I declare:package Tie::Annotate; use base qw(Tie::FileHandle::Base); use IO::File; use strict; use warnings; sub TIEHANDLE { my $class = shift; my $annotation = shift; my $handle = new IO::File ">> test.err" or die "Cannot open file: +$!\n"; #$self->{FH} = *$FH; return bless {FH => $handle, ann => $annotation}, $class; } sub PRINT { my $self = shift; my $string = shift; my $handle = $self->{FH}; print $handle "$self->{ann} " . $string; } 1;
tie *STDOUT, "Tie::Annotate", 'OUT'; tie *STDERR, "Tie::Annotate", 'ERR';
And this generally works correctly, outputting to STDOUT gets appended to the error log with OUT at the start of the line and STDERR gets appended to the error log with ERR and the start of the line.
But there is a problem; one of the CPAN modules (Cvs) relies on IPC::Run which dies when STDERR and STDOUT are captured like this.
FWIW the actual error message is
Can't call method "slave" on an undefined value at /home/FCS/teh/perl/lib/perl5/site_perl/5.8.5/IPC/Run.pm line 2816
IPC::Run's verion is $VERSION = " 0.80";
Is there something crazy with what im trying to do?
A suggestion of a better way to catch STDOUT and STDERR would be appreciated if there is any... Unfortunatly, Log4Perl is not an option.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: How to log all output from a program?
by shmem (Chancellor) on Oct 15, 2007 at 08:01 UTC | |
by salva (Canon) on Oct 15, 2007 at 08:25 UTC | |
by shmem (Chancellor) on Oct 15, 2007 at 08:50 UTC | |
by salva (Canon) on Oct 15, 2007 at 09:10 UTC | |
by salva (Canon) on Oct 16, 2007 at 21:42 UTC | |
Re: How to log all output from a program?
by bart (Canon) on Oct 15, 2007 at 10:37 UTC | |
Re: How to log all output from a program?
by Corion (Patriarch) on Oct 15, 2007 at 13:52 UTC | |
Re: How to log all output from a program?
by DrHyde (Prior) on Oct 15, 2007 at 11:37 UTC | |
Re: How to log all output from a program?
by dokkeldepper (Friar) on Oct 15, 2007 at 08:26 UTC | |
by deorth (Scribe) on Oct 15, 2007 at 09:48 UTC |