spawn-please
Easy and small child_process.spawn
Last updated 3 months ago by raine .
ISC · Repository · Bugs · Original npm · Tarball · package.json
$ npm install spawn-please 
SYNC missed versions from official npm registry.

spawn-please

npm version

Easy and small child_process.spawn.

  • Promise-based
  • Cross-platform
  • Pass stdin as an argument
  • Rejects on a non-zero exit code by default

Install

npm install spawn-please

Usage

(
  command: string,
  args?: string[],
  options?: Options,
  spawnOptions?: any,
): Promise<{
  stdout: string
  stderr: string
  code: number | null
}>
import spawn from 'spawn-please'

const { stdout, stderr } = await spawn('printf', ['please?'])

assert.equal(stdout, 'please?')
assert.equal(stderr, '')

Options

  • rejectOnError: boolean - Rejects with a SpawnError if the process exits with a non-zero exit code. Default: true.
  • stdin: string - Send stdin to the spawned child process.
  • stdout: (data: string) => void - Stream stdout by chunk.
  • stderr: (data: string) => void - Stream stderr by chunk.

Errors

A process that exits with a non-zero exit code rejects with a SpawnError, which keeps the output that was collected before it failed:

import spawn, { SpawnError } from 'spawn-please'

try {
  await spawn('npm', ['ls', '--json'])
} catch (err) {
  if (err instanceof SpawnError) {
    console.log(err.code) // 1
    console.log(err.stdout) // still usable, even though npm exited non-zero
  }
}

A process that cannot be spawned at all, e.g. the command is not installed, rejects with the underlying ENOENT error. rejectOnError: false does not apply to it, since nothing ran.

License

ISC © Raine Revere

Current Tags

  • 4.0.0                                ...           latest (3 months ago)

11 Versions

  • 4.0.0                                ...           3 months ago
  • 3.0.0                                ...           3 years ago
  • 2.0.2                                ...           3 years ago
  • 2.0.1                                ...           4 years ago
  • 2.0.0                                ...           4 years ago
  • 1.0.0                                ...           6 years ago
  • 0.4.1                                ...           6 years ago
  • 0.4.0                                ...           6 years ago
  • 0.3.0                                ...           9 years ago
  • 0.2.0                                ...           10 years ago
  • 0.1.0                                ...           11 years ago
Maintainers (1)
Downloads
Total 37
Today 1
This Week 1
This Month 18
Last Day 0
Last Week 1
Last Month 13
Dependencies (1)
Dev Dependencies (4)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE