in reply to Handling STDERR when using Net::OpenSSH
The Capture::Tiny module can be used to capture STDERR. For example,
gives the output:#!/usr/bin/env perl use strict; use warnings; use Net::OpenSSH; use Capture::Tiny ':all'; my $host = 'broken'; my $ssh; my ($stdout, $stderr, @result) = capture { $ssh = Net::OpenSSH->new($host); }; print "Captured STDERR: $stderr\n"; $ssh->error and die "Couldn't establish SSH connection: ". $ssh->error +; exit;
Captured STDERR: ssh: Could not resolve hostname broken: nodename nor +servname provided, or not known Couldn't establish SSH connection: unable to establish master SSH conn +ection: master process exited unexpectedly at ns.pl line 15.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Handling STDERR when using Net::OpenSSH
by mds (Novice) on Aug 21, 2013 at 13:39 UTC |
In Section
Seekers of Perl Wisdom