Built-in routines

File & process IO

Full

Read and write files, run subprocesses — real in Raku++, but there's no browser filesystem.

Interpreter Native (--exe) Browser

Raku++ can read and write files and launch subprocesses, exactly as Rakudo does. The browser playground has no filesystem and can't spawn processes, so these examples are shown with their verified output (from the interpreter and --exe) rather than a Run button.

Running a subprocess #

run launches an external command; with :out you capture its standard output.

not in browser
my $r = run "echo", "from a subprocess", :out;
say $r.out.slurp(:close).chomp;
Output
from a subprocess

Writing and reading a file #

spurt writes a whole string to a path; slurp (or .lines) reads it back. Here a temp file is written, its lines counted and indexed, then removed.

not in browser
my $f = $*TMPDIR.add("spec-io-demo.txt");
spurt $f, "alpha\nbeta\ngamma\n";
say $f.lines.elems;
say $f.lines[1];
$f.unlink;
Output
3
beta

Notes #