$ npm install spawn-please
Easy and small child_process.spawn.
npm install spawn-please
(
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, '')
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.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.
ISC © Raine Revere
© 2010 - cnpmjs.org x YWFE | Home | YWFE