I use:
sub sshSendCommand {
my ($self, $cmd, $pollTime) = @_;
my $chan = $self->{ssh}->channel();
my $log = '';
my $timeDelta = sprintf "%4d:", time() - $self->{startTime};
$pollTime ||= 500;
print "$timeDelta ssh: <$cmd> (poll time: $pollTime)\n";
$chan->exec($cmd);
my @poll = {handle => $chan, events => ['in']};
while ($self->{ssh}->poll($pollTime, \@poll)) {
if ($poll[0]{revents}{channel_closed}) {
print "$timeDelta channel closed\n";
last;
}
next if !$poll[0]{revents}{in};
my $buff;
$log .= $buff while $chan->read($buff, 1024);
next;
}
print "$log\n$timeDelta ssh command complete\n";
return $log;
}
True laziness is hard work