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

    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\