in reply to Sending STDERR to a filehandle

You are redirecting STDERR to STDOUT with '2>&1' and you're sending the STDOUT from the command to /dev/null with '1>/dev/null'. You then print each line of output from the command to STDOUT (which now will be the STDERR of the command) in the while loop.

Replies are listed 'Best First'.
Re: Re: Sending STDERR to a filehandle
by sauoq (Abbot) on Jun 09, 2003 at 20:22 UTC

    I think you may have misunderstood his intentions. He wants to discard the usual stdout of the program and read its usual stderr via the pipe. He is doing that by duping stderr to stdout and redirecting stdout to /dev/null. The way he has it should work.

    -sauoq
    "My two cents aren't worth a dime.";
    
Re: Re: Sending STDERR to a filehandle
by Anonymous Monk on Jun 09, 2003 at 18:08 UTC
    Thats my problem, it's not making it into the while loop.
      Are you sure? Try this on for size:
      my $cmd = q(perl -e 'die'); my $pid = open(ERROR, "$cmd 2>&1 1>/dev/null |"); print "$pid\n"; while (<ERROR>) { print "ERROR: $_\n"; }