in reply to A little demo for Net::SSH2
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; }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: A little demo for Net::SSH2
by Always Improving (Initiate) on Oct 15, 2010 at 18:27 UTC | |
by zentara (Archbishop) on Oct 15, 2010 at 20:03 UTC | |
by Anonymous Monk on Oct 29, 2010 at 18:14 UTC | |
by zentara (Archbishop) on Oct 30, 2010 at 10:33 UTC | |
by afoken (Chancellor) on Oct 30, 2010 at 11:37 UTC | |
by Anonymous Monk on Nov 01, 2010 at 14:35 UTC | |
|
In Section
Cool Uses for Perl