McDarren has asked for the wisdom of the Perl Monks concerning the following question:
My problem is that the redirection (2>&1) within the piped open does not work as expected. If I deliberately force $cmd to return an error, it still comes to _my_ STDERR, rather than the STDOUT of the CMD filehandle.sub TestRadiusAuth { my $cmd = "$radclient" . " -t $radius_config->{auth_timeout}" . " -r $radius_config->{auth_retries}" . " -i 1 $radius_config->{ip}:$radius_config->{auth_port}" . " auth $radius_config->{secret} <<EOF\n" . "User-Name = \"$test_user\"\n" . "Password = \"$test_pass\"\n" . "NAS-IP-Address = \"$eth0\"\n" . "EOF\n"; my $response; open(CMD, "$cmd 2>&1 |") or die "Could not execute $cmd:$!\n"; while (<CMD>) { chomp(); return (1,$_) if /Session-Timeout/; $response .= $_; } return (0,$response); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Capturing STDERR from a piped open
by McDarren (Abbot) on Aug 13, 2005 at 16:03 UTC | |
|
Re: Capturing STDERR from a piped open
by tlm (Prior) on Aug 13, 2005 at 15:30 UTC | |
by McDarren (Abbot) on Aug 13, 2005 at 15:45 UTC | |
by tlm (Prior) on Aug 13, 2005 at 15:55 UTC | |
|
Re: Capturing STDERR from a piped open
by graff (Chancellor) on Aug 13, 2005 at 15:33 UTC | |
by tlm (Prior) on Aug 13, 2005 at 15:38 UTC |