I found that some of the commands I was running over ssh (from Windows to an HP-UX system) were returning early from the read loop (and terminating the command), so I had to add extra code for executing and reading the results. This was part of a larger module, but the relevant method was:
sub cmd {
my $self = shift;
my $cmd = shift;
my $ssh = $self->{ssh};
my $ch = $self->{ch};
unless ($ch) {
$self->{ch} = $ch = $ssh->channel;
$ch->ext_data('merge');
$ch->blocking(0);
$ch->shell();
1 while <$ch>;
}
print $ch "$cmd\n";
select(undef, undef, undef, 0.2);
print $ch "print SSH2_cmd_done\n";
select(undef, undef, undef, 0.2);
my @output;
READ_LOOP: while (1) {
local $_;
while (<$ch>) {
last READ_LOOP if /^SSH2_cmd_done/;
push @output, $_;
}
sleep 1;
}
return @output;
}
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.