Skip to content

std/proc

Running commands and controlling the current process. Import with import "std/proc";.

run and exit work on the native backend and Node. capture, pid, and abort are native only.

int run(cmd: string)

Runs cmd through the system shell, with output going to the program’s own stdout and stderr. Blocks until the command finishes and returns its exit status.

let status = proc.run("ls -l");
if (status != 0) {
io.print("command failed");
}
string capture(cmd: string)

Runs cmd through the system shell and returns its captured standard output. Returns "" if the command could not be started, so an empty result is indistinguishable from failure.

let branch = str.trim(proc.capture("git branch --show-current"));
int pid()

Returns this process’s id.

void exit(code: int)

Terminates the process immediately with the given exit code. Never returns.

if (fatal) {
proc.exit(1);
}
void abort()

Terminates abnormally (raises SIGABRT). Use exit for normal termination. abort signals a bug and may produce a core dump.