I'm trying to write a quick program which will execute a series of
commands on the remote system and get each individual exit status back
from the commands.
It appears the way to go about doing this is to create a new channel,
exec, get the exit status, destroy the channel, exec, get the exit
status, etc.
However, I *also* want to grab the output of these commands (stdout and
stderr) in real time, so I'm trying to use poll.
Now, I could be going about this completely the wrong way. If I am,
please let me know :)
$channel->shell doesn't seem like it fits for me as I don't think I can
get the exit statuses back from the remote commands being run.
Here's a bit of what I have so far (which isn't working):
my $channel = $ssh->channel;
$channel->exec("sleep 5 && echo 'moo' && sleep 1");
print "\n";
while (1) {
print "loop\n";
my @poll = ({handle => $channel, events => ['in','err']});
if ($ssh->poll(500, \@poll)) {
# handle events
}
print Dumper($poll[0]->{revents});
}
everything is all well and good until the command finishes (after the
sleep 5), when polling completely blocks. Nothing further ever happens.
If I kill the remote sshd process handling the connection (the
user@notty process) then it returns these events:
$VAR1 = {
'in' => 1,
'value' => 129,
'listener_closed' => 1,
'channel_closed' => 1
};
Is there some step I'm missing to make this work how I want?
-Jeremy
|