spawn-but-with-promises
v1.0.2
Published
child_process.spawn but as a promise
Readme
spawn-but-with-promises
Works identically to child_process.spawn() but is also a promise. Implementation including types is less than 50 lines.
Install
npm install -s spawn-but-with-promisesUsage
import { spawn } from 'spawn-but-with-promises';
const process = spawn('echo', ['hello', 'world']);
process.stdout.on('data', (d) => {
console.log(d.toString());
});
await process;
console.log('process finished.');
The promise resolves to the processes exit code. If you want to throw an exception when the exit code isn't 0, pass rejectOnNonZero: true:
const process = spawn('ls', ['/this/will/fail'], {
rejectOnNonZero: true
});