use IPC::Open2;
use File::Spec;
use Scalar::Util qw( blessed );
+use Capture::Tiny qw( capture_stderr );
our @EXPORT_OK = qw(
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;
};