Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Getting PERL to snarf STDERR

by toku (Novice)
on Mar 01, 2002 at 19:52 UTC ( #148667=perlquestion: print w/ replies, xml ) Need Help??
toku has asked for the wisdom of the Perl Monks concerning the following question:

I want to run a program and collect STDOUT from it like this:
$a = `some_obsure_and_eclectic_command`;
My problem is that this command also spits out data on STDERR.
I want to redirect STDERR to /dev/null or something simalar.

Any thoughts?

Comment on Getting PERL to snarf STDERR
Re: Getting PERL to snarf STDERR
by Rich36 (Chaplain) on Mar 01, 2002 at 19:56 UTC
    You can do just that by using the standard open command.
    open(STDERR, ">/dev/null"); $a = `some_obsure_and_eclectic_command`; close(STDERR);

    Rich36
    There's more than one way to screw it up...

      Many thanks.
      It worked perfectly.
Re: Getting PERL to snarf STDERR
by VSarkiss (Monsignor) on Mar 01, 2002 at 20:03 UTC

    Most perls use a Bourne-type shell to run backticks, and you can redirect specific descriptors within that: $a = `some_obscure_and_eclectic_command 2>/dev/null`;

Re: Getting PERL to snarf STDERR
by PrakashK (Pilgrim) on Mar 01, 2002 at 20:04 UTC
    $a = `some_obsure_and_eclectic_command 2> /dev/null`;

    /prakash

Re: Getting PERL to snarf STDERR
by gellyfish (Monsignor) on Mar 01, 2002 at 22:38 UTC

    for future reference you might find perlfaq8 quite useful in this regard

    /J\

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://148667]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2015-02-27 23:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    On my keyboard, Caps lock is:








    Results (457 votes), past polls