in reply to Q: Cannot get the capture from connection with Net::Openssh?
The die instruction is actually invoked and the print sentences below never reached.$ssh->error and die "remote ls command failed: " . $ssh->error;
Instead, write it as follows:
use Net::OpenSSH; use Net::OpenSSH::Constants qw(:error); ... my ($output, $errput) = $ssh->capture2({tty => 1}, $xxx); if ($ssh->error and $ssh->error != OSSH_SLAVE_CMD_FAILED) { die "remote ls command failed: " . $ssh->error; } print "OUT: $output\n"; print "ERR: $errput\n"; print "RC: $?\n";
Note also that in Perl, (@array, $scalar) = whatever() is never what you want because @array "eats" all the values returned by whatever(), and $scalar always becomes undef.
That's the reason why Net::OpenSSH->capture2(...) returns just two scalars in all the occasions, while Net::OpenSSH->capture(...) can be more clever and return lines in list context or one scalar with the full output in scalar context.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Q: Cannot get the capture from connection with Net::Openssh?
by ryder (Initiate) on May 05, 2015 at 09:54 UTC |