redirect stderr and stdout to same file 
Author Message
 redirect stderr and stdout to same file

Hi,
 I'm running a perl script which calls several other perl scripts and other programs
(written in C COBOL or whatnot).(this is for NT 4.0 machine).
I want to redirect all STDOUT and STDERR to the same log file, to appear in the "right"
order.
I've tried

#! .../perl

$| = 1 ; # for flushing the buffers
open (STDOUT , ">> $filename");
open (STDERR, ">> $filename");

.
.
.

and it does not work - the stderr output of C programs come always before all the other
output (stderr and stdout of the perl and stdout of C).

Any ideas?




Fri, 01 Sep 2000 03:00:00 GMT  
 redirect stderr and stdout to same file

Quote:

> I want to redirect all STDOUT and STDERR to the same log file, to appear
> in the "right" order.

Have you tried CGI::Carp.pm ?
This module has a built-in error - redirection function - and it's part
of the Perl standard distribution, as far as I know.

Joergen
--
-------------------------------------------------------------------
   "Everything is possible - even sometimes the impossible"
             HOELDERLIN EXPRESS - "Touch the void"
-------------------------------------------------------------------



Fri, 01 Sep 2000 03:00:00 GMT  
 redirect stderr and stdout to same file

Quote:

> Hi,
>  I'm running a perl script which calls several other perl scripts and other programs
> (written in C COBOL or whatnot).(this is for NT 4.0 machine).
> I want to redirect all STDOUT and STDERR to the same log file, to appear in the "right"
> order.
> I've tried

> #! .../perl

> $| = 1 ; # for flushing the buffers

> open (STDERR, ">> $filename");

        You might try closing the handles before the open calls. My
guess is that since you are not checking the return of open() here
you are missing the failure.

        Austin

#! .../perl

$| = 1 ; # for flushing the buffers
close (STDOUT);
close (STDERR);
open (STDOUT, ">> $filename") || warn "Couldn't open $filename, $!";
open (STDERR, ">> $filename") || warn "Couldn't open $filename, $!;



Fri, 01 Sep 2000 03:00:00 GMT  
 redirect stderr and stdout to same file

Quote:

>I want to redirect all STDOUT and STDERR to the same log file, to appear in the "right"
>order.
>I've tried

>#! .../perl

>$| = 1 ; # for flushing the buffers
>open (STDOUT , ">> $filename");
>open (STDERR, ">> $filename");

a)  $| works on an open filehandle.   So you need to set it _after_
    the opens.

b)  You need to set it for each filehandle.

So put this after the opens:

   select STDERR; $| = 1; select STDOUT; $| = 1;

And _always_ check the return from open.

Mike Guy



Tue, 05 Sep 2000 03:00:00 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. how to redirect stderr and stdout to same file

2. assigning STDERR whild redirecting STDOUT to a file

3. Redirecting STDOUT/STDERR to a file

4. redirect stderr and stdout to the same file

5. HELP - with redirect of STDERR and STDOUT

6. redirect STDERR to STDOUT ?????

7. redirecting stderr and stdout

8. writing to terminal even with STDOUT and STDERR redirected

9. Problem with redirecting STDOUT and STDERR

10. How to redirect STDOUT,STDERR and keep the message order

11. Redirect stderr to stdout w/ Perl under Unix?

12. Redirecting STDERR to STDOUT (on NT)

 

 
Powered by phpBB® Forum Software