Skip to main content

Module child_process

Module child_process 

Source
Expand description

Node child_process module — real subprocess execution via std::process::Command.

The synchronous entry points (execSync, spawnSync, execFileSync) are fully implemented: they spawn the child with piped stdio, wait for it, and return its captured output. stdout/stderr are returned as Buffers by default (built through buffer::from_bytes, identical to the fs module’s byte returns) or as strings when an encoding other than "buffer" is given in the options object.

The asynchronous forms are backed synchronously here because node-js has no socket-driven child event loop:

  • exec(cmd, cb) runs the command to completion, then delivers the result through its callback (error, stdout, stderr) scheduled as a microtask (queue_micro), matching Node’s “callback fires after the current tick” ordering. stdout/stderr are strings, as Node’s exec default.
  • execFile(file, args, cb) is exec without a shell — file is run directly with the args array — and additionally returns a (non-live) ChildProcess-shaped object carrying the collected result.
  • spawn(cmd, args) runs the command to completion up front and returns a minimal ChildProcess-shaped object carrying the already-collected pid, exitCode, stdout and stderr. LIMITATION: because these run synchronously, the returned object is not live — .on('close'|'exit', …) listeners registered by the caller after the call do not fire (the process has already finished and its output is exposed as properties).

fork(modulePath) is the exception: it spawns THIS node executable on modulePath as a genuinely live child and returns a live ChildProcess emitter that fires exit/close when the process terminates and supports .kill(). Its IPC channel (.send() / process.on('message')) is NOT implemented — see the fork fn doc for why.

Constants§

CHILD_PROCESS_METHODS
Instance method names for the ChildProcess @@native tag, exposed to stdlib::instance_has_method (property reads that yield a bound method).
METHODS

Functions§

call
instance_call
stdlib::instance_call entry for a ChildProcess receiver. EventEmitter methods delegate to events; process-control methods act on the live child (only forked children are live — a spawn/execFile result has already exited, so kill is a no-op there).