Updated
Hi,

After consulting the Cookbook (16.7), I've written the following sub.
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); }
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.

I figure that I'm doing something fundamentally stupid, but I can't see it for the life of me.
Would appreciate any advice.

In reply to Capturing STDERR from a piped open by McDarren

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.