Unfortunately it is not so simple as linking ssh stderr stream back to Perl through a pipe as it would block the child if you don't read from it at the right times, and that means going into the select loop at the core of Net::SFTP::Foreign.
But there is a simple work around, just send ssh stderr to a file and read it afterwards:
use Net::SFTP::Foreign; use File::Temp; my $hostname = 'localhost'; my $ssherr = File::Temp->new or die "File::Temp->new failed"; open my $stderr_save, '>&STDERR' or die "unable to dup STDERR"; open STDERR, '>&'.fileno($ssherr); my $sftp = Net::SFTP::Foreign->new($hostname, more => ['-v']); # the child ssh process has already been created with the redirected S +TDERR # so we can reset it on the parent: open STDERR, '>&'.fileno($stderr_save); if ($sftp->error) { print "sftp error: ".$sftp->error."\n"; seek($ssherr, 0, 0); while (<$ssherr>) { print "captured stderr: $_"; } } close $ssherr;
In reply to Re^2: Net::SFTP::Foreign Connection STDERR
by salva
in thread Net::SFTP::Foreign Connection STDERR
by allyc
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |