Built-in routines

File & process IO

Full

Read and write files, run subprocesses — real in Raku++; the browser has files but no processes.

Interpreter Native (--exe) Browser

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

Files are a different story: the WebAssembly build inherits an in-memory filesystem from Emscripten, so the spurt/slurp example below does work in a browser — against a /tmp that lives in the tab's memory, starts empty and vanishes when the page reloads.

Running a subprocess #

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

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.

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 #