Skip to content

Commit

Permalink
Fall back to shell() if Proc::Async is unavailable
Browse files Browse the repository at this point in the history
  • Loading branch information
hoelzro committed Aug 6, 2015
1 parent c1cb313 commit 26bc902
Showing 1 changed file with 29 additions and 13 deletions.
42 changes: 29 additions & 13 deletions lib/Panda/Common.pm
Expand Up @@ -73,24 +73,40 @@ class X::Panda is Exception {
}
}

my $has-proc-async = Proc::<Async>:exists;

sub run-and-gather-output(*@command) is export {
my $output = '';
my $stdout = '';
my $stderr = '';
my $passed;

my $proc = Proc::Async.new(|@command);
$proc.stdout.tap(-> $chunk {
print $chunk;
$output ~= $chunk;
$stdout ~= $chunk;
});
$proc.stderr.tap(-> $chunk {
print $chunk;
$output ~= $chunk;
$stderr ~= $chunk;
});
my $p = $proc.start;
my $passed = $p.result.exitcode == 0;
if $has-proc-async {
my $proc = Proc::Async.new(|@command);
$proc.stdout.tap(-> $chunk {
print $chunk;
$output ~= $chunk;
$stdout ~= $chunk;
});
$proc.stderr.tap(-> $chunk {
print $chunk;
$output ~= $chunk;
$stderr ~= $chunk;
});
my $p = $proc.start;
$passed = $p.result.exitcode == 0;
}
else {
my $cmd = @command.map({ qq{"$_"} }).join(' ');
$output ~= "$cmd\n";
my $p = shell("$cmd 2>&1", :out);
for $p.out.lines {
.chars && .say;
$output ~= "$_\n";
}
$p.out.close;
$passed = $p.exitcode == 0;
}

:$output, :$stdout, :$stderr, :$passed
}
Expand Down

0 comments on commit 26bc902

Please sign in to comment.