in reply to Capturing STDERR from a piped open

FWIW, it works fine for my (on Linux):

use strict; use warnings; my $cmd = 'ls nonexistent'; open( CMD, "$cmd 2>&1 |" ) or die "Could not execute $cmd: $!\n"; while ( <CMD> ) { chomp; print "<< $_ >>\n"; } __END__ % perl 483558.pl << ls: nonexistent: No such file or directory >>

the lowliest monk

Replies are listed 'Best First'.
Re^2: Capturing STDERR from a piped open
by McDarren (Abbot) on Aug 13, 2005 at 15:45 UTC
    Thanks,
    Your example works fine for me too, so I've updated my original post to show the full subroutine.

    $cmd calls radclient to do a test auth against a remote radius server. If I deliberately cause an error, say for example using an incorrect port (causing "radclient: no response from server"), it still comes to _my_ STDERR when I run it.

    Any clues?

      AFAICT, you're trying to feed the external program's stdin through a here-doc, which looks quite hopeless to me. Read what the Good Cookbook has to say about accessing stdin, stdout, and stderr of another process (recipe 16.9, pp. 639-641).

      Update: I guess it was not so hopeless after all. :-/

      the lowliest monk