in reply to Re^2: Printing Output From Net::SSH2 exec
in thread Printing Output From Net::SSH2 exec

Indeed, I've had more success with shell, but as salva points out, occasionally I end up with partial output. The other thing is that it's hard to distinguish stderr from stdout when running a command under shell.

It seems like Net::SSH2 has a new maintainer, so hopefully that module will start to see some improvement soon. In the meantime, it looks like Net::OpenSSH is the way to go for me.

R
  • Comment on Re^3: Printing Output From Net::SSH2 exec

Replies are listed 'Best First'.
Re^4: Printing Output From Net::SSH2 exec
by PiLIT888 (Initiate) on Aug 20, 2009 at 19:44 UTC
    Net::SSH2 is working for me. Commands that take a while to return back to shell are fine now:

    my $ssh2 = Net::SSH2->new();
    $ssh2->connect("$host") or die $!;
    my $chan = $ssh2->channel();
    $chan->blocking(1);
    $chan->exec("rpm -qa |wc|awk '{print \$1}'");
    $chan->read($buf, $len);
    my @output;
    while (<$chan>) { push(@output,$_); }
    my $stdout=join ("", @output);
    print $stdout;