LogoPear Docs
ReferencesBareModules

bare-subprocess

Reference for bare-subprocess: native process spawning for Bare, with an API close to the Node.js child_process module.

stable

bare-subprocess spawns and manages child processes from Bare. The API follows the Node.js child_process module. It's a native addon and requires Bare >=1.7.0; it's available on desktop (Windows, macOS, Linux).

npm i bare-subprocess

Usage

const { spawn } = require('bare-subprocess')

const subprocess = spawn('echo', ['hello', 'world'], { stdio: 'inherit' })

subprocess.on('exit', () => console.log('done'))

API

Spawning

const subprocess = spawn(file[, args][, options])

Spawn a child process, returning a Subprocess.

const result = spawnSync(file[, args][, options])

Synchronously spawn a child process and return its result once it exits.

Subprocess

A Subprocess exposes pid, spawnfile, spawnargs, stdio, stdin, stdout, stderr, exitCode, signalCode, killed, connected, and channel.

subprocess.kill([signum])

Send a signal to the child (default SIGTERM).

subprocess.send(message[, handle][, callback]) · subprocess.disconnect()

Send a message (and optionally a handle) over the IPC channel, or close it.

subprocess.ref() · subprocess.unref()

Keep the event loop alive for the child, or release it.

A Subprocess emits exit, close, message, disconnect, and error.

Parent side

Inside a spawned process, the parent interface mirrors the channel: parent.connected, parent.send(message[, handle][, callback]), parent.disconnect(), parent.ref(), parent.unref(), and the message, disconnect, and error events.

Builds on bare-env, bare-events, bare-os, bare-pipe, bare-structured-clone, bare-tcp, and bare-url (see Bare modules).

See also

  • Bare modules—the full bare-* catalog.
  • bare-os—process IDs, signals, and environment.
  • Bare runtime APIBare.Thread for in-process concurrency instead of child processes.

On this page