Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: Synchronizing STDERR and STDOUT

by ikegami (Patriarch)
on Sep 21, 2006 at 15:39 UTC ( [id://574163]=note: print w/replies, xml ) Need Help??


in reply to Synchronizing STDERR and STDOUT

some way of telling the source process to send everything to the same filehandle

open(STDERR,'>&', STDOUT); creates a new filehandle (so it doesn't help), but *STDERR = *STDOUT; makes both STDOUT and STDERR refer to the same filehandle. You don't even need to turn off buffering.

use IO::Handle (); open(STDERR,'>&', STDOUT); print("STDOUT = ", fileno(STDOUT), "\n"); # 1 print("STDERR = ", fileno(STDERR), "\n"); # 2 print STDOUT 'a'; print STDERR 'b'; print STDOUT 'c'; STDOUT->flush(); # ac STDERR->flush(); # b print("\n"); *STDERR = *STDOUT; print("STDOUT = ", fileno(STDOUT), "\n"); # 1 print("STDERR = ", fileno(STDERR), "\n"); # 1 print STDOUT 'a'; print STDERR 'b'; print STDOUT 'c'; STDOUT->flush(); # abc STDERR->flush();

Of course, this doesn't work if you fork.

If you can't modify the program, you can replace
perl script.pl
with
perl -e "*STDERR = *STDOUT; do 'script.pl'"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://574163]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (2)
As of 2024-04-19 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found