Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: redirect stdout into hash

by doctorspears (Novice)
on Jun 13, 2012 at 19:53 UTC ( [id://976058]=note: print w/replies, xml ) Need Help??


in reply to Re^3: redirect stdout into hash
in thread redirect stdout into hash

#!/usr/software/bin/perl -w use strict; use warnings; use Net::SSH2; my $ssh = Net::SSH2->new(); $ssh->debug(0); my $bigcmd = "priv set diag; wafl_susp -w"; my @array; $ssh->connect("10.61.92.10",22); my $pass = 'P@ssw0rd'; $ssh->auth(username => 'root', password =>$pass ); if($ssh->auth_ok()) { runcmd(my_channel($ssh), "$bigcmd"); } print "----------------------------------------------\n"; foreach (@array) { print "$_\n"; } sub runcmd { my ($channel, $command) = @_; @array = <$channel>; $channel->exec($command);# or die $@ . $ssh->error(); my $buff; while(!$channel->eof()) { my $buff; $channel->read($buff, 1024); } my $rc = $channel->exit_status(); $channel->close(); return $rc; } sub my_channel { my $ssh = shift(@_); my $chan = $ssh->channel('session'); $chan->blocking ( 0 ); $chan->flush(); $chan->ext_data('merge'); return $chan; }

results in

@cycsnane01:( ~/_Scripts/) $ ./waflsusp.pl ----------------------------------------------

Replies are listed 'Best First'.
Re^5: redirect stdout into hash
by aaron_baugher (Curate) on Jun 13, 2012 at 20:47 UTC

    You're reading from the channel before you execute the command through it. Look at my example again.

    Aaron B.
    Available for small or large Perl jobs; see my home node.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://976058]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-20 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found