The output streams are being buffered and flushed to the output device at
different times. You want to turn on auto-flush for both STDOUT and STDERR
(see perlfaq5). Here's a demo:

 print "Start\n";

 $old_fh = select(STDERR);
 $| = 1;
 select($old_fh);
 $| = 1;

 print STDOUT "STDOUT 1\n";
 print STDERR "STDERR 1\n";
 print STDOUT "STDOUT 2\n";
 print STDERR "STDERR 2\n";
 print "Done\n";

If you put this in a file called test.pl and run it like this:

 perl test.pl >file.txt 2>&1

you will get the output in the order that the script produced it.



> -----Original Message-----
> From: Wening Andreas [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, June 06, 2002 7:56 PM
> To: '[EMAIL PROTECTED]'
> Subject: redirection of STDERR
> 
> 
> Hi all,
> 
> I posted a similar question a while ago but the answers didn't really
> resolve my problem.
> 
> I want to redirect all output in a file. Therefore I start my 
> script like:
> myscript.pl >>logfile.txt
> 
> That works fine for STDOUT but all error messages don't get 
> into that file,
> no I got the suggestion to do:
> myscript.pl >>logfile.txt 2>&1
> 
> That adds the STDERR output to my file but not at the right 
> time. So my log
> file contains all the STDOUT output and then all the STDERR 
> output. I want
> to have the errormessages exactly then written to the logfile 
> when they
> happen and I'm wondering if I can redirect the stream to STDOUT like:
> open STDERR, ">> STDOUT"
> 
> But this didn't work. I also tried to write to the same file like:
> open STDERR, ">> logfile.txt";
> but this didn't work too (I guess I can assign a file only to 
> one output
> stream).
> 
> Can anybody help?
> 
> Andreas 
> 
> 
> 
> _______________________________________________
> Perl-Win32-Admin mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to