> -----Message d'origine-----
> De : [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] De la part de zentara
> Envoyé : samedi 25 juin 2005 13:36
> À : beginners@perl.org
> Objet : Re: route STDOUT to file
> 
> 
> There are a whole bunch of different ways, ...
> 

Here yet another one ;)

#!/usr/bin/perl
use strict;
use warnings;
use IO::Handle;

{
 local *STDOUT;
 local *STDERR;
 local *FILE;

 open FILE, ">log.txt" || die "Cannot write to log file!";
 open STDOUT, ">&FILE" || die "Cannot redirect STDOUT";
 open STDERR, ">&FILE" || die "Cannot redirect STDERR";

 STDOUT->autoflush(1);
 STDERR->autoflush(1);

 print STDOUT "A\n"; #to log.txt
 print STDERR "B\n"; #to log.txt
}

#after above {}, STDOUT and STDERR
#go back their original condition
print STDOUT "C\n"; #on the console
print STDERR "D\n"; #on the console

R,
José.



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to