capture-spawn
v1.0.1
Published
Asynchronously capturing spawn output.
Downloads
774
Readme
capture-spawn
Asynchronously capturing spawn output.
Install
npm i capture-spawn --save
Usage
For more use-cases see the tests
const captureSpawn = require('capture-spawn')
captureSpawn
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}: Passedcp
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) // => 'hello charlike world\n'
console.log('buffer', buf) // => <Buffer ...>
console.log('result === buffer.toString()', buf.toString()) // => 'hello charlike world\n'
})
console.log(cp === stream) // => true
Error handling
Where
buffer
is thestderr
output andcode
can bestring
ornumber
.
var proc = spawn('node', ['not-exist', 'something'])
captureSpawn(proc, console.log)
// => SpawnError {
// name: 'SpawnError',
// message: '',
// code: 1,
// buffer: <Buffer 6d 6f 64 75 ...>
// }
Related
- capture-stream: Capture stream output. | homepage
- cross-spawn: Cross platform child_process#spawn and child_process#spawnSync | homepage
- cross-spawn-async: Cross platform child_process#spawn | homepage
- function-arguments: Get arguments of a function, useful for and used in dependency injectors.… more | homepage
- gitclone-defaults: Powerful and flexible signature for
gitclone
- defaults, checks, validating, etc. | homepage - parse-git-config: Parse
.git/config
into a JavaScript object. sync or async. | homepage - parse-git-log: Parse default
git log
style to array of objects from git repository… more | homepage - run-commands: Cross-platform run series of commands or in parallel flow. Run commands in… more | homepage
- spawn-commands: Launches a new process with the given command, with command line arguments… more | homepage
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.