Skip to content

Commit

Permalink
Use Bufs and utf8-c8 in get-output
Browse files Browse the repository at this point in the history
Otherwise Greppable complains about malformed UTF-8. Maybe a good
side-effect of this change is that some output will not be normalized.

See issue #153.
  • Loading branch information
AlexDaniel committed Jun 25, 2018
1 parent 62a8d0d commit 04beb80
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions lib/Whateverable.pm6
Expand Up @@ -243,24 +243,25 @@ sub get-output(*@run-args, :$timeout = $default-timeout || 10,
$proc.bind-stdin: $fh-stdin
}

my @chunks;
my $buf = Buf.new;
my $result;
my $s-start = now;
my $s-end;
react {
whenever $proc.stdout { @chunks.push: $_ }; # RT #131763
whenever $proc.stderr { @chunks.push: $_ };
whenever $proc.stdout :bin { $buf.push: $_ }; # RT #131763
whenever $proc.stderr :bin { $buf.push: $_ };
whenever Promise.in($timeout) {
$proc.kill; # TODO sends HUP, but should kill the process tree instead
@chunks.push: «timed out after $timeout seconds»
$buf.push: «timed out after $timeout seconds».encode
}
whenever $proc.start: :$ENV, :$cwd { #: scheduler => BEGIN ThreadPoolScheduler.new { # TODO do we need to set scheduler?
$result = $_;
$s-end = now;
done
}
}
my $output = @chunks.join;

my $output = $buf.decode: utf8-c8;
%(
output => $chomp ?? $output.chomp !! $output,
exit-code => $result.exitcode,
Expand Down

0 comments on commit 04beb80

Please sign in to comment.