Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Suppress/Reactivate STDERR

by ikegami (Patriarch)
on Dec 15, 2006 at 23:55 UTC ( [id://590160]=note: print w/replies, xml ) Need Help??


in reply to Suppress/Reactivate STDERR

STDERR is not necessarily the same thing as file descriptor 2 (and it isn't after you do *STDERR = *OLDERR;). For commands executed by system, file descriptor 2 is stderr. They have no knowledge of the file descriptor associated with your program's STDERR variable.

Replace
*STDERR = *OLDERR;
with
open STDERR, ">&OLDERR";

Update: s/3/2/g. Thanks nobull.

Replies are listed 'Best First'.
Re^2: Suppress/Reactivate STDERR
by nobull (Friar) on Dec 16, 2006 at 16:31 UTC
    STDERR is not necessarily the same thing as file descriptor 3
    s/3/2/

    In recent Perl there's no need to use package variables for file handles to achieve this.

    open my $olderr, '>&', \*STDERR or die $!; #... open STDERR, '>&', $olderr or die $!;

      Re: 2 vs 3 -- Thanks, typo!

      Re: lexical file handles -- True. I just went along with the code that was already there. Lexicals can be used for file handles since Perl 5.6.0.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2024-04-23 10:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found