Built-in routines
File & process IO
FullRead 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 subprocessWriting 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
betaNotes #
- File handling:
spurt/slurpfor whole files,openfor a handle,.lines/.wordsto iterate,IO::Pathmethods (.e,.d,.add,.unlink) for paths. run/shellstart subprocesses;:out/:errcapture their streams.$*TMPDIR,$*CWD,$*HOMEareIO::Pathhandles to standard locations.- None of this exists in the browser sandbox — run such programs with the interpreter (
rakupp program.raku) or a compiled binary (rakupp --exe program.raku).