allspawn

1.1.2 • Public • Published

allspawn

© Harald Rudell created ECMAScript 2049 in December 2017. ISC License

Benefits

Execute commands using async/promises

Full error handling, ability to capture stdout and stderr as well as the child process object

Usage

import {spawnAsync, spawnCapture, SpawnShim, SpawnAsync, SpawnPipe} from 'allspawn'

async spawnAsync({args, options, cpReceiver, echo, capture, stderrFails, nonZeroOk})
 resolves to:
  capture: false: Number 0
   nonZeroOk: true: may return non-zero number
   signalOk: true: may return string signal like 'SIGTERM'
  capture: true: {stdout, stderr, status, signal}
args: array of string arguments, the first string is the command
options: optional object as defined by Node.js spawn (cwd env argv0 stdio detached uid gid shell windowsVerbatimArguments windowsHide)
options.timeout: the process is killed if not completing in timeout ms, default infinite
options.silent: optional bolean default false: do not echo to the parent process’ stdout and stderr, ie. if true the child process executes silently.
options.stdio: default no stdin and echo to stdout and stderr.
cpReceiver: an object that will receive the child process object as property cp
echo: optional boolean, default false: command and arguments are printed
capture: optional boolean, default false: stdout and stderr are captured, up to options.maxBuffer bytes (200 KiB)
stderrFails: optional boolean, default false: any output to stderr will cause error. If capture is true, the error is thrown at end of process, otherwise on first print.
nonZeroOk: optional boolean, default false: if the child process reurns a status code other than zero, return it instead of throwing an error.
signalOk: optional boolean, default false: if the child process is terminated by a signal, the signal string is returned instead of an error thrown.

{stdout} async spawnCapture({args, …})
Like spawnAsync but with defaults helpful for executing system commands from node programs.
stderrFails: true, so that echo to stderr causes error
capture: true, so that output is captured
options.timeout: the process is killed if not completing within 3 s
options.silent: true, the process executes silently
Return value: unlike SpawnAsync, if stdout or stderr has a terminating newline, it is removed

SpawnAsync
This is the class implementation for spawnAsync, ie. spawnAsync(o) is new SpawAsync(o).startSpawn()

SpawnShim
This is a promise shim around child_process.spawn, like it needs to work in 2018.

© Harald Rudell created ECMAScript 2049 in December 2017. ISC License

Package Sidebar

Install

npm i allspawn

Weekly Downloads

19

Version

1.1.2

License

ISC

Unpacked Size

33.6 kB

Total Files

7

Last publish

Collaborators

  • haraldrudell