Skip to content

Instantly share code, notes, and snippets.

@rurban
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rurban/9605572 to your computer and use it in GitHub Desktop.
Save rurban/9605572 to your computer and use it in GitHub Desktop.
rakudo: parrot openpipe with rurban/openpipe-env-gh1065
sub QX($cmd) {
#if? parrot
my $pipe := pir::new__Ps('FileHandle');
my $env := pir::new__Ps('Env');
$pipe.set_keyed('env', $env);
$pipe.open(nqp::unbox_s($cmd), 'rp');
fail "Unable to execute '$cmd'" unless $pipe;
$pipe.encoding('utf8');
my $result := $pipe.readall;
$pipe.close();
store_dynlex_safely('$!', $pipe.exit_status);
$result
#?endif
#?if !parrot
my Mu $pio := nqp::openpipe(nqp::unbox_s($cmd), nqp::cwd(), nqp::getenvhash(), '');
fail "Unable to execute '$cmd'" unless $pio;
my $result = nqp::p6box_s(nqp::readallfh($pio));
nqp::closefh($pio);
$result;
#?endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment