Thanks for the quick reply

Here is the full logic.

$session = Net::SSH2->new(); $rc = $session->connect($target_ip, $target_port, Timeout=>4000) ; $session->auth_password($username, $passwd) ; $chan = $session->channel(); $chan->shell() ; print $chan $cmd . " \n" ; my @poll = ({handle=>$chan, events=>['in', 'ext', 'channel_closed']}); my $job_done = 1; my $status; while ($job_done > 0) { $session->blocking(0) ; $session->poll(1, \@poll) ; if ($poll[0]->{revents}->{in}) { while (<$chan>) { $resp .= $_ ; } $status = 0 ; if ($chan->eof()) { $status = $chan->exit_status() ; } } if ($poll[0]->{revents}->{ext}) { my ($len, $buff) ; while ($len = $chan->read($buff, 1024, 1)) { $resp .= $buff ; } if (! $resp) { $status = $chan->exit_status() || 0 ; } } elsif ($poll[0]->{revents}->{channel_closed}) { while (<$chan>) { $resp .= $_ ; } $status = $chan->exit_status() ; } if ($chan->eof() || $poll[0]->{revents}->{ext} || ($poll[0]->{revents}->{channel_closed} && $status == 0)) { $chan->close ; $job_done = -1; } $session->blocking(1) ; } print "\nresponse : $resp";

The problem here is, commands that take more than 5 seconds to respond returns null. Whereas, commands that takes less time to respond are returning the exact result

This is where sleep comes into picture for me

Please help.


In reply to Re^2: Net::SSH2 channel returns no output by rama133101
in thread Net::SSH2 channel returns no output by rama133101

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.