in reply to Re^2: Jammed FH pipe
in thread Jammed FH pipe
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.
|
|---|