Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 506
mattbh Avatar asked Jan 10 '11 04:01

mattbh


Video Answer


2 Answers

As of Jan 2015:

Recently verified tutorial page

Recent Perl 6 advent page

Recent discussion of rationalizing what gets returned by what

like image 24
raiph Avatar answered Oct 13 '22 22:10

raiph


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

like image 117
mattbh Avatar answered Oct 13 '22 23:10

mattbh