How to execute an external command and capture its output in perl6?

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.)


As of Jan 2015:

Recently verified tutorial page

Recent Perl 6 advent page

Recent discussion of rationalizing what gets returned by what


This can also be done safely (without touching a shell) using run() with the out parameter:

my $proc = run 'ls', q!/tmp/"This" is an ugly name, isn't it?/!, :out;
my $output = $proc.out.slurp-rest;

More details available in the Proc class.