From: Robert 'phaylon' Sedlacek Date: Wed, 20 Jun 2012 20:02:57 +0000 (+0000) Subject: more command error handling fixes X-Git-Tag: v0.001_001~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=ff4d9e13b7a10316ae73a025d173f8c34f0230a3;p=scpubgit%2FSystem-Introspector.git more command error handling fixes --- diff --git a/lib/System/Introspector/Probe/FileHandles.pm b/lib/System/Introspector/Probe/FileHandles.pm index 9b72367..a3289b2 100644 --- a/lib/System/Introspector/Probe/FileHandles.pm +++ b/lib/System/Introspector/Probe/FileHandles.pm @@ -2,7 +2,7 @@ package System::Introspector::Probe::FileHandles; use Moo; use System::Introspector::Util qw( - handle_from_command + lines_from_command transform_exceptions ); @@ -11,9 +11,9 @@ has lsof_command => (is => 'ro', default => sub { 'lsof' }); sub gather { my ($self) = @_; return transform_exceptions { - my $pipe = $self->_open_lsof_pipe; + my @lines = lines_from_command [$self->_lsof_command_call]; my @handles; - while (defined( my $line = <$pipe> )) { + for my $line (@lines) { chomp $line; my @fields = split m{\0}, $line; push @handles, { map { @@ -25,10 +25,9 @@ sub gather { }; } -sub _open_lsof_pipe { +sub _lsof_command_call { my ($self) = @_; - my $lsof = $self->lsof_command; - return handle_from_command "$lsof -F0"; + return $self->lsof_command, '-F0'; } 1; diff --git a/lib/System/Introspector/Util.pm b/lib/System/Introspector/Util.pm index 530f9f9..c73572b 100644 --- a/lib/System/Introspector/Util.pm +++ b/lib/System/Introspector/Util.pm @@ -56,7 +56,8 @@ sub output_from_command { $in = '' unless defined $in; my ($out, $err) = ('', ''); - my $ok = run($command, \$in, \$out, \$err); + my $ok = eval { run($command, \$in, \$out, \$err) or die $err}; + $err = $@ unless $ok; return $out, $err, $ok if wantarray; $command = join ' ', @$command