I'm trying to read the output of a command issued using Net::SSH2. For some reason if I do not set the buffer size in the $chan2->read to close to the length of result the command does not finish. The output length is varies from about 20 bytes to over 2048. If I turn on debug ($ssh2->debug(1);) I see bytes being read but no completion. I've tried the two blocking's (ssh and channel) to no avail. I have similar issues with the write and exec options. Is there a better way to do this ? Keep in mind that I'm not the most powerful Perl programmer. And no I can't use expect. Sample code:

#!/opt/csw/bin/perl use strict; use warnings; use Net::SSH2; use constant BUFLEN => 10_0000; my $host = "<name or IP>"; my $user = "<ID>"; my $pass = "<password>"; my $buf; my $ssh2 = Net::SSH2->new(); my $ok = 1; print "==> $host\n"; $ssh2->connect($host) or $ok = 0; if ( !$ok ) { print "Probable telnet\n"; exit(1); } if ( !$ssh2->auth_password( $user, $pass ) ) { print "==> 4 pass fail\n"; exit(1); } my $chan2 = $ssh2->channel(); $chan2->shell(); print $chan2 ("term len 0\n"); $chan2->read( $buf, BUFLEN ); print $buf; print $chan2 ("dir\n"); $chan2->read( $buf, BUFLEN ); print $buf;

In reply to Getting variable sized reapones using Net::SSH2 by essej1

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.