I'm using a library method repeatedly which makes similar system calls. The problem is, because of a possible fault in a new IOS release the piped command appears to be jamming the filehandle, following calls to the method fail badly. method summary
sub if ($? > 0 ) { $? = 0; } if ( defined(SNMP) ) { close SNMP; } print " /@/ gettable called ($?)\n"; my ($target,$table,$fieldstring,$comstr) = @_; $snmpCmd = "mibtable -table $table -fields $fieldstring -node $ta +rget |"; open (SNMP, $snmpCmd ) || die print STDERR "Couldn't open pipe +: $! \/ $? \/ $@\n"; $error = $?; while (<SNMP>) { # do stuff } my $closed = 13; $closed = close (SNMP) || $! ? "Error closing sort pipe: $!" : "Exit status $? from sort"; print "\tDid filehandle get closed: '$closed'\n"; undef SNMP; print STDERR "!!!! $! \/ $? \/ $@\n";
The first call to this method appears to works fine, even though the child process prints an error to STDERR. The method completes normally. Subsequent calls fail. Here's the output, the test script hits two separate mibtable, if the order is reversed, the second one would succeed.
dncms@case3 ~ 621 > perl testSnmp2.pl node /@/ gettable called (0) snmpCmd: 'mibtable -table table1 -fields fields1 -node node |' pid: 1168 -1- (bootflash + 65451748 65536000) -2- (sw1-slot2-dfc-bootflash + 15990784 15990784) -3- (sw1-slot3-dfc-bootflash + 15990784 15990784) -4- (sw1-slot6-dfc-bootflash + 15990784 15990784) -5- (sw1-slot7-dfc-bootflash + 15990784 15990784) Error retrieving information from node No response arrived before timeout Did filehandle get closed: 'Exit status 256 from sort' !!!! / 256 / END GETTABLE (What is $?: 256) Errno from pipe: (piped exit code: 1) / (signal: 0) / (core dump: 0) [ +0] What is $?: 256 /@/ gettable called (0) snmpCmd: 'mibtable -table table1 -fields fields2 -node node |' pid: 1171 Error retrieving information from node No response arrived before timeout Did filehandle get closed: 'Exit status 256 from sort' !!!! / 256 / END GETTABLE What is $?: 256
All I know is that the 'mibtable' command is returning "Error retrieving information from node No response arrived before timeout" to STDERR and $? is being set to 256. Despite the filehandle SNMP being closed and undeffed, subsequent attempts to use the method fail because, presumably, the filehandle is jammed in some way. It doesn't clear until the perl script exits. BTW- I'm using Perl 5.6.1. Any ideas how to clear the FH so I can reuse the method? Thanks!

In reply to 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.