Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Net-SSH2 CPAN distribution.

Report information
The Basics
Id:
43150
Status:
rejected
Priority:
Low/Low
Queue:

People
Owner:
Nobody in particular
Requestors:
mvrk [...] sapo.pt
Cc:
AdminCc:

BugTracker
Severity:
Normal
Broken in:
0.18
Fixed in:
(no value)



Subject: problem passing net:ssh2 object to another function
I've divided my program in 3 subs, ssh_connect,ssh_exec,ssh_disconnect. I create my ssh2 object in the connect sub, and if the connection is sucessfull i return it. Then in the main program i pass ssh2 object to the exec and disconnect sub. Then i run ssh_exec($ssh,"ls -l") it simply doesn't do anything, not even an error. I'm i doing anyting wrong or is this a bug? Heres my code: use Net::SSH2; use Net::SSH2::Channel; sub ssh_connect{ my $ip=$_[0]; my $myuser=$_[1]; my $mypass=$_[2]; my $ssh2 = Net::SSH2->new(); $ssh2->poll(1); $ssh2->connect($ip); $login = $ssh2->auth_password($myuser, $mypass); if ($login){ return $ssh2; } else{ return 0; } } sub ssh_exec{ my $ssh2=$_[0]; my $cmd=$_[1]; $chan = $ssh2->channel(); $chan->blocking(0); $chan->exec($cmd); my $poll = { handle => $chan, events => -1 }; while ($ssh2->poll(500, [ $poll ])) { if ($poll->{revents}{out}) { #print "Out event is set\n"; while (<$chan>) { $r=$r.$_; } } if ($poll->{revents}{channel_closed} || $poll->{revents}{listener_closed}) { my $exit = $chan->exit_status(); return $r; } } print "Timeout occurred while executing (".$cmd.").\n"; return 0; } sub ssh_disconnect{ my $ssh2=$_[0]; $ssh2->disconnect(); } my $ssh = ssh_connect("127.0.0.1","user","password"); if ($ssh == 0){ print "Connection failed.\n"; exit; } $r = ssh_exec($ssh,"ls-l"); print $r; ssh_disconnect($ssh); print "Finished.\n"; exit;
"ls-l" is an invalid program. The remote shell invokes it and returns an error via stderr but you are only looking at stdin and so you see nothing coming. Anyway, what you probably want is "ls -l"!


This service runs on Request Tracker, is sponsored by The Perl Foundation, and maintained by Best Practical Solutions.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.