Spawn Promise
December 19, 2022 · View on GitHub
Child Process Spawn as a Promise, with simple in/out piping
Install
npm install @ahmadnassri/spawn-promise
API
spawn (command [, args] [, options] [, input])
identical to [child_process.spawn][node-spawn] in every way, except:
- writes the
inputvalue tostdin, - on success returns a Promise that is fulfilled with a simple object containing both
stdout&stderrbuffers. - on failure returns a Promise rejected with a
SpawnErrorerror object containing bothstdout&stderrbuffers.
Usage
const spawn = require('@ahmadnassri/spawn-promise')
const options = {
env: process.env
}
// success
spawn('grep', ['f'], options, 'foo')
.then(streams => console.log(streams.stdout))
Author: Ahmad Nassri • Twitter: @AhmadNassri