in reply to redirect stdout into hash
use warnings; use Net::SSH2; use Data::Dumper; my $ssh = Net::SSH2->new(); # make a global hash for storage my %hash; # make a global counter for incrementing the hash keys my $counter = 0; ...... ...... if($ssh->auth_ok()) { runcmd(my_channel($ssh), "$bigcmd"); } # read output ( but lines may be split ) print $DATA::Dumper( \%hash ),"\n"; __END__ sub runcmd { my ($channel, $command) = @_; $channel->exec($command);# or die $@ . $ssh->error(); my $buff; while(!$channel->eof()) { my $buff; $channel->read($buff, 1024); # print $buff; $hash{$counter} = $buf; $counter++; } my $rc = $channel->exit_status(); $channel->close(); return $rc; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: redirect stdout into hash
by doctorspears (Novice) on Jun 13, 2012 at 18:09 UTC | |
by zentara (Cardinal) on Jun 13, 2012 at 19:48 UTC | |
by doctorspears (Novice) on Jun 13, 2012 at 20:25 UTC |