Overview
Host process control and child process lifecycle.
Process covers the running program: command-line arguments, the
environment, the working directory, the process id, and exit. Two
ways to start a child:
Process.run()waits for the child, captures stdout and stderr, and returns the exit code with both buffers.Process.spawn()returns immediately with aChildProcesshandle. The caller owns waiting, reading, and killing.
SpawnOptions wires each of the three child streams separately
(Stdio.Inherit, Stdio.Piped, Stdio.Null), sets the child working
directory, and passes an environment table. Children start from a
cleared environment: only PATH (plus SYSTEMROOT on Windows) is
forwarded from the host, then the entries in SpawnOptions.env.
Anything else the child needs has to be listed explicitly.
import { Process } from "@std/process";
let out = Process.run("echo", ["hello"]);
print(out.exitCode);
print(out.stdoutText());Spawning is subject to the sys:exec grant. Without it the runtime
stops the program with [S401]: Unapproved Child Process, and a
command that cannot be started aborts the process.
When to use it
Reach for @std/process to control the host (args, env, cwd, exit) or to run children: Process.run captures a command to completion, while spawn plus ByteBuffer pipes drives interactive children. Always wait() what you spawn.
Capabilities
- Host control
- spawn/run lifecycles
- ByteBuffer pipes
Symbols
- class ChildProcess — Live child process. Either
wait()for the exit code or let the - class Process — Host process surface: argv, environment, cwd, identity, exit,
- class ProcessOutput — Captured result of
Process.run(): exit code plus buffered - class SpawnOptions — Spawn configuration: working directory, environment overrides merged
- enum Stdio