If you just can't get IO::Tee to work, write your own:
This function will print to both STDERR and a specified in
logfile. The syntax to use it is:
writeit("Your String\n", $YOUR_LOGFILE);
Here's the function:
sub writeit{
my $string = shift @_;
my $LOG = shift @_;
open (LOGFILE, ">> $LOG") || die "can't open $LOG: $!";
LOGFILE->autoflush(1);
STDERR ->autoflush(1);
@log_array = ( LOGFILE, STDERR );
foreach $logfile (@log_array) {
print $logfile $string
}
close(LOGFILE) || die "can't close $LOG: $!";
}
I think this could be cleaned up a wee bit but it works.
Cheers,
Carter.
> -----Original Message-----
> From: Martin Moss [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, August 21, 2002 7:58 AM
> To: [EMAIL PROTECTED];
> [EMAIL PROTECTED]
> Subject: Re: Teeing STDERR?
>
>
> I use a set of Modules I wrote to do something simillar.
> Bficient::Logger.
>
> It simply ties, STDERR (& optionally STDOUT) to a log file,
> and reformats
> each output with a time, date, PID and ProcessName. Whilst
> this doesn't
> duplicate output, I'm sure it could do with a few simple
> additions, to the
> backend module.
>
> the basic principle is:-
> save STDERR
> close STDERR
>
> open STDERR, > $logfile
> use a sub module to catch different types of output. (print etc..)
>
> To make it print to multiple files would be as simple as not
> closing the
> original STDERR, printing the message to the original STDERR
> as well as the
> new logfile STDERR.
>
> If you would like I could post a copy of the module,
>
> Regards
>
> Marty
>
>
>
> ----- Original Message -----
> From: "Philip Morley" <[EMAIL PROTECTED]>
> To: <[EMAIL PROTECTED]>;
> <[EMAIL PROTECTED]>
> Sent: Wednesday, August 21, 2002 2:11 PM
> Subject: RE: Teeing STDERR?
>
>
> >
> > It's only 3 pages long, I've seen far worse Perl documentation ;-)
> >
> > Here's a simple example of teeing STDERR using IO::Tee:
> >
> > use strict;
> > use IO::Tee;
> >
> > open(ERRFILE, ">C:/errors.txt") || die "Error opening file: $!\n";
> > my $tee = IO::Tee->new(\*STDERR, \*ERRFILE);
> >
> > print $tee "This is an error that will print to STDERR and
> errors.txt\n";
> >
> > close ERRFILE;
> >
> > HTH,
> >
> > Phil Morley
> >
> >
> >
> > |---------+----------------------------------------------->
> > | | Beckett Richard-qswi266 |
> > | | <[EMAIL PROTECTED]> |
> > | | Sent by: |
> > | | [EMAIL PROTECTED]|
> > | | veState.com |
> > | | |
> > | | |
> > | | 21/08/02 13:08 |
> > | | |
> > |---------+----------------------------------------------->
> >
> >-------------------------------------------------------------
> --------------
> ---------------------|
> > |
> |
> > | To: [EMAIL PROTECTED]
> |
> > | cc:
> |
> > | Subject: RE: Teeing STDERR?
> |
> >
> >-------------------------------------------------------------
> --------------
> ---------------------|
> >
> >
> >
> > I looked it up, but don't understand it's documentation. Is there an
> easier
> > to use module, or can anyone tell me how to do it with IO::Tee?
> >
> > Thanks.
> >
> > R.
> >
> > > There is a module called IO::Tee, which should do what
> you are asking.
> > >
> > > Regards,
> > >
> > > Phil Morley
> >
> >
> > > Hi folks,
> > >
> > > I want to have STDERR output to the screen in the normal way,
> > > but I also
> > > want it logged to a file, which can be overwritten each time
> > > the program
> > > runs. I tried:
> > >
> > > open (STDERR, "| tee > err.txt") or die "can't redirect
> STDERR: $!\n";
> > >
> > > which should work under unix, but as I'm using active state
> > > perl under W2K,
> > > I get the following error:
> > >
> > > 'tee' is not recognised as an internal or external
> command, operable
> > > program
> > > or batch file.
> > >
> > > What's the best way to do this?
> > >
> > > Thanks.
> > >
> > > R.
> > _______________________________________________
> > Perl-Win32-Users mailing list
> > [EMAIL PROTECTED]
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> >
> >
> >
> >
> >
> >
> > _______________________________________________
> > Perl-Win32-Users mailing list
> > [EMAIL PROTECTED]
> > To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> >
>
> _______________________________________________
> Perl-Win32-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs