Child process
child_process.spawnSync()
Runs a child and blocks until it completes. Suitable for small offline CLI setup tasks, not hot request paths. Inspect error, status and signal separately. Tested on Node.js 22.16.0. Example output (one line per entry): ["3 null true"].
Formal Syntax & Structure
nodejs syntaxnodejs
spawnSync(command[, args][, options])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| command | string | Executable. |
| args | string[] | Arguments. |
| options | object | Process settings. |
Return Value
object
Result containing status and output.
Working Example
Example Snippetnodejs
import { spawnSync } from 'node:child_process';const r = spawnSync(process.execPath, ['-e', 'process.exitCode=3'], { timeout: 1000, encoding: 'utf8', env: {} });console.log(r.status, r.signal, r.error === undefined);