Skip to content

Instantly share code, notes, and snippets.

@donaldh
Created October 9, 2013 14:14
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 donaldh/6901992 to your computer and use it in GitHub Desktop.
Save donaldh/6901992 to your computer and use it in GitHub Desktop.
my class IO::Pipe does IO {
method open($command, *%opts) {
my Mu $env := nqp::getattr(%*ENV, EnumMap, '$!storage');
my Mu $pio := nqp::openpipe(nqp::unbox_s($command), $*CWD.Str, $env, '');
fail "Unable to execute '$command'" unless $pio;
my $pipe := IO::Handle.new();
nqp::bindattr($pipe, IO::Handle, '$!PIO', $pio);
$pipe;
}
method from($command, *%opts) {
self.open($command, |%opts);
}
method to($command, *%opts) {
self.open($command, |%opts);
}
}
my $pipe = IO::Pipe.from('cat CREDITS');
say $pipe.lines.join("\n");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment