Hello lovers of the great perl,
I have a problem with Net::OpenSSH which I don't quite understand.
My code calls a find command on a remote machine where I'm not able to run perl on so I just grab some information and process it somewhere else.
My problem is that capture2() does return undef in stdout when the result of the executed cli command starts with "00" (from my understanding).

$find = "find $args->{'path'}/ -name '$args->{'foo'}.*' -newer ~/start +.txt ! -newer ~/end.txt | xargs grep -vh 'H\\|T' | awk -F, '{ if( \$1 + !~ /\\// & & \$1 >= $args->{'start'} && \$1 < $args->{'end'}){"; for (my $i = 1; $i <= $indices; $i++){ $find .= "if(\$$args->{'index'.$i} ~ /^[0-9]+\$/ && \$$args->{'ind +ex'.$i} >= $args->{'min'.$i} && \$$args->{'index'.$i} <= $args->{'max +'.$i} ){ print \$$args->{'index'.$i} }"; } $find .= "}}' | sort | uniq -c | awk '{print \$2,\",\",\$1}'"; ($edr,$stderr) = $args->{'ssh'}->capture2($find); if($stderr){ print $stderr;} @edr = split /\n/, $edr;
That's the relevant output from debug where the cli command returns "00 , 99":
# io3 mloop, cin: 0, cout: 1, cerr: 0 # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 8 at offset 0 #> 30 30 20 2c 20 39 39 0a + | 00 , 99. # io3 fast, cin: 0, cout: 1, cerr: 0 # stdout, bytes read: 0 at offset 8 # leaving _io3() # _waitpid(22920) => pid: 22920, rc: Use of uninitialized value $edr in split at /home/bo/scripts/test.pl l +ine 338.
This debug output shows a working example:
# io3 mloop, cin: 0, cout: 1, cerr: 1 # io3 fast, cin: 0, cout: 1, cerr: 1 # stdout, bytes read: 15 at offset 0 #> 39 39 30 31 30 32 20 2c 20 32 30 34 36 32 0a + | 990102 , 20462. # io3 fast, cin: 0, cout: 1, cerr: 1 # stdout, bytes read: 0 at offset 15 # stderr, bytes read: 0 # leaving _io3() # _waitpid(22922) => pid: 22922, rc:
The cli sommand returns "990102 , 20462" and the script runs fine.
I noticed that stderr is missing in the previous debug output. Sometimes the cli comamnd returns more than one line that's why I split $edr into an array.
In the beginning I uses capture() instead of capture2() but I needed the stderr for troubleshooting so I stuck to it.
My understanding of the Net::OpenSSH code is not that good, so I'm asking for help, maybe it is intentionally returning undef. Thank you for your time, tuckito

In reply to Confused with Net::OpenSSH - capture2()? by tuckito

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.