node:child_process provides Node’s process APIs: spawn, exec,
execFile, their Sync forms, fork, and ChildProcess.
Example
js
// child.mjs
import { execFile, execFileSync } from "node:child_process";
import { promisify } from "node:util";
console.log(execFileSync("echo", ["hello"], { encoding: "utf8" }).trim());
const { stdout, stderr } = await promisify(execFile)("sh", ["-c", "echo out; echo err >&2"]);
console.log(JSON.stringify({ stdout, stderr }));
try {
execFileSync("sh", ["-c", "exit 3"]);
} catch (error) {
console.log("exit status", error.status);
}
utf-8 · js · Lines: 14
elide run child.mjs prints:
text
hello
{"stdout":"out\n","stderr":"err\n"}
exit status 3
utf-8 · text · Lines: 3
Differences from Node
fork()starts another Elide script;child.send()andprocess.send()exchangemessageevents.process.execPathruns Elide:execFileSync(process.execPath, ["--snippet", 'process.stdout.write("hi")']).--allow-runand--deny-runapply under the sandbox.
Samples
Reference
Status: Full · Not measured · since 1.1.0
Exports
| Export | Kind | Status | Notes |
|---|---|---|---|
exec(), execSync() | function | Full | Executes a command in a shell |
execFile(), execFileSync() | function | Full | Executes a file without a shell |
spawn(), spawnSync() | function | Full | Spawns a new process using the given command |
fork() | function | Full | Spawns a new Node.js process using the given module path |