From: Robert 'phaylon' Sedlacek Date: Fri, 15 Jun 2012 01:37:06 +0000 (+0000) Subject: more fixes for external command error handling X-Git-Tag: v0.001_001~48 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=23b83532980abcf243e8b9bf45081de656f30a26;p=scpubgit%2FSystem-Introspector.git more fixes for external command error handling --- diff --git a/lib/System/Introspector/Util.pm b/lib/System/Introspector/Util.pm index 98d2429..99788ef 100644 --- a/lib/System/Introspector/Util.pm +++ b/lib/System/Introspector/Util.pm @@ -6,6 +6,7 @@ use IPC::Run qw( run ); use IPC::Open2; use File::Spec; use Scalar::Util qw( blessed ); +use Capture::Tiny qw( capture_stderr ); our @EXPORT_OK = qw( handle_from_command @@ -78,11 +79,20 @@ sub handle_from_command { local $@; my $ok = eval { my $out; - my $child_pid = open2($out, File::Spec->devnull, $command); - my @lines = <$out>; - waitpid $child_pid, 0; + my $child_pid; + my @lines; + my ($err) = capture_stderr { + $child_pid = open2($out, File::Spec->devnull, $command); + @lines = <$out>; + close $out; + waitpid $child_pid, 0; + }; my $content = join '', @lines; my $status = $? >> 8; + $err = "Unknown error" + unless defined $err; + fail "Command error ($command): $err\n" + if $status; open $pipe, '<', \$content; 1; };