package System::Introspector::Util;
use Exporter 'import';
use IPC::Run qw( run );
+use IPC::Open2;
+use File::Spec;
+use Scalar::Util qw( blessed );
our @EXPORT_OK = qw(
handle_from_command
sub handle_from_command {
my ($command) = @_;
- open my $pipe, '-|', $command
- or fail "Unable to read from command '$command': $!";
+ my $pipe;
+ local $@;
+ my $ok = eval {
+ my $out;
+ my $child_pid = open2($out, File::Spec->devnull, $command);
+ my @lines = <$out>;
+ waitpid $child_pid, 0;
+ my $content = join '', @lines;
+ my $status = $? >> 8;
+ open $pipe, '<', \$content;
+ 1;
+ };
+ unless ($ok) {
+ my $err = $@;
+ die $err
+ if blessed($err) and $err->isa('System::Introspector::_Exception');
+ fail "Error from command '$command': $err";
+ }
return $pipe;
}