How can I execute an external command and capture its output in Perl6?
Perl5-style back-ticks don't seem to work:
> my $results = `ls`;
Confused at line 1, near "my $results"
Synopsis 16 documents the run method, but this returns the exit status rather than the output from stdout.
I'm using the Rakudo implementation (rakudo-star-2010.12).
As of Jan 2015:
Recently verified tutorial page
Recent Perl 6 advent page
Recent discussion of rationalizing what gets returned by what
Use qqx or qx instead, e.g.:
> my $results = qqx{ls};
Larry Wall answered an equivalent question on a mailing list:
[...]
: What replaces backtick or qx{} ?
qqx[] or qq:x[] would be the exact equivalent. qx[] or q:x[] would be the same with single-quote semantics. (There are probably no backticks for that purpose since we're reserving ` for user-defined stuff, and because backticks are visually difficult to tell from single quotes in many fonts.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With