Created
October 16, 2012 16:14
-
-
Save AlD/3900298 to your computer and use it in GitHub Desktop.
Net::SSH2 poll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $cmd = '/bin/cat /proc/cpuinfo'; | |
my $chan = $ssh->channel; | |
$chan->exec($cmd); | |
my $buf; | |
my @poll = ( { handle => $chan, | |
events => [ 'in', 'ext', 'channel_closed' ], }, | |
); | |
POLL: while ( $ssh->poll(1000, \@poll) ) { | |
my ($continue, $last) = (0, 0); | |
foreach my $event (keys(%{$poll[0]->{revents}})) { | |
if ($event =~ /^(in|ext)$/) { | |
$continue = 1; | |
my $ext = $event eq 'ext'; | |
$chan->read($buf, 1024, $ext); | |
print($buf); | |
} elsif ($event =~ /^channel_closed$/) { | |
$last = 1; | |
} | |
} | |
if ($last and not $continue) { | |
last POLL; | |
} | |
}; | |
my $exit = $chan->exit_status; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment