Skip to content

node:child_process

How Elide supports Node's child_process: spawn, exec, execFile and their Sync forms, fork() with IPC between Elide scripts, and sandbox flags.

On this page

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() and process.send() exchange message events.
  • process.execPath runs Elide: execFileSync(process.execPath, ["--snippet", 'process.stdout.write("hi")']).
  • --allow-run and --deny-run apply under the sandbox.

Samples

Reference

Status: Full · Not measured · since 1.1.0

Exports

ExportKindStatusNotes
exec(), execSync()functionFullExecutes a command in a shell
execFile(), execFileSync()functionFullExecutes a file without a shell
spawn(), spawnSync()functionFullSpawns a new process using the given command
fork()functionFullSpawns a new Node.js process using the given module path

Was this page helpful?