I just noticed the 5.6 limit now. That explains some of the reasons my code won't do for you.

Reverting to using $snmpCmd is wrong though. Sure, you'll need to provide the command as a string in 5.6, but you don't properly convert the args into shell literals at the moment.

Nothing in my code can output "!!!! Illegal seek / 0 /", so I don't know anything about that.

I get the following response: Can't wait for child: with an $? value of 256.

Looks like there's a bug in Perl's design. There's no reliable way to tell if close returns a system error ($!) or a child error ($?)*.

( On second thought, we'll get the wrong error message at worse, so I will use $!==0 )

sub to_shell_literal { my ($s) = @_; #return $s if m{^[a-zA-Z0-9/_-]+\z}; $s =~ s/'/'\\''/g; return "'$s'"; } sub { my ($target, $table, $fieldstring, $comstr) = @_; my @cmd = ( mibtable => ( -table => $table, -fields => $fieldstring, -node => $target, ); my $cmd = join ' ', map to_shell_literal($_), @cmd; open(my $fr_child, "$cmd |") or die("Can't launch $cmd[0]: $!\n"); while (<$fr_child>) { # do stuff } if (!close($fr_child)) { die("Can't wait for child: $!\n") if $! != 0; die("Child died from signal ", $? & 0x7F, "\n") if $? & 0x7F; die("Child died with code ", $? >> 8, "\n") if $? >> 8; die("Unknown error waiting for child\n"); } print("Child exited successfully\n"); }

* — Yeah, the documentation says $! will be zero in this instance, but I don't trust it. At least one other instance where the docs ignored "$! is only meaningful on error" has turned out to be wrong.


In reply to Re^3: Jammed FH pipe by ikegami
in thread Jammed FH pipe by gryf

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.