Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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?

Replies are listed 'Best First'.
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);

    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`;


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


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://148667]
Approved by root
[Lady_Aleena]: My blasted web host will not put perl 5.22 in /usr/bin/perl, it is in /usr/local/cpanel/ 3rdparty/bin/perl
Lady_Aleena has been banging her head against this wall for years now with no success on breaking the wall.

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2017-04-28 06:33 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (519 votes). Check out past polls.