Skip to content

Instantly share code, notes, and snippets.

@AlD
Created October 16, 2012 16:14
Show Gist options
  • Save AlD/3900298 to your computer and use it in GitHub Desktop.
Save AlD/3900298 to your computer and use it in GitHub Desktop.
Net::SSH2 poll
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