Asynchronously capturing spawn output.
Install
npm i capture-spawn --save
Usage
For more use-cases see the tests
const captureSpawn = require('capture-spawn')
Capture output of asynchronous spawn
.
Params
cp
{Stream}: Child process spawn stream.callback
{Function}: Gets error, result or result buffer - cb(err, res, buf)
.returns
{Stream}: Passed cp
stream.
Example
var captureSpawn = require('capture-spawn')
var spawn = require('cross-spawn-async')
var cp = spawn('echo', ['hello charlike', 'world'])
var stream = captureSpawn(cp, function callback (err, res, buf) {
if (err) return console.error(err)
console.log('result', res)
console.log('buffer', buf)
console.log('result === buffer.toString()', buf.toString())
})
console.log(cp === stream)
Error handling
Where buffer
is the stderr
output and code
can be string
or number
.
var proc = spawn('node', ['not-exist', 'something'])
captureSpawn(proc, console.log)
Related
Contributing
Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.