Re: STDOUT and STDERR to same file



On 08/29/2006 09:06 AM, Ken Foskey wrote:
I have a daemon process that works but I am currently running it with

script.pl > error.log 2>&1

and I want to do the same thing without using the redirection,, remove
the human error when starting the program.

I can `open( STDERR, '>', 'error.log') ...` but is there a piece of
magic to duplicate that to STDOUT as well (ie same file output)

Ta
Ken Foskey



"Perldoc -f open" shows you how to create duplicate file handles, e.g.:

use strict;
use warnings;
open (FH, '>out') or die("Failure:$!\n");
open (STDOUT, '>&FH') or die ("Dup failure: $!\n");
open (STDERR, '>&FH') or die ("Dup failure: $!\n");
print "STDOUT text is here.\n";
print STDERR "This might be an ERROR message.\n";
close (FH);

__END__

HTH


.



Relevant Pages

  • Re: STDOUT and STDERR to same file
    ... On 8/29/06, Ken Foskey wrote: ... and I want to do the same thing without using the redirection,, remove ... the human error when starting the program. ... you could use tee(man 1 tee). ...
    (perl.beginners)
  • Re: STDOUT and STDERR to same file
    ... Ken Foskey wrote: ... and I want to do the same thing without using the redirection,, remove ... the human error when starting the program. ... magic to duplicate that to STDOUT as well ...
    (perl.beginners)