buffered-spawn
Buffered child_process#spawn.
Installation
$ npm install buffered-spawn
Why
- Easy to use
- Uses cross-spawn that fixes windows issues
- Supports callback & promise style
Usage
In terms of arguments, they are equal to node's spawn.
var buffspawn = require('buffered-spawn');
buffspawn('git', ['clone', 'git@github.com/bower/bower'], { cwd: '~/foo' }, function (err, stdout, stderr) {
if (err) {
return console.err('Command failed with error code of #' + err.status);
}
console.log(stdout);
console.log(stderr);
});
buffspawn('git', ['clone', 'git@github.com/bower/bower'], { cwd: '~/foo' })
.spread(function (stdout, stderr) {
console.log(stdout);
console.log(stderr);
}, function (err) {
console.err('Command failed with error code of #' + err.status);
});
When using promises you can also get feedback via progress:
buffspawn('git', ['clone', 'git@github.com/bower/bower'])
.progress(function (buff) {
console.log(buff.toString());
})
.spread(function (stdout, stderr) {
console.log('---------------------------');
console.log(stdout);
console.log(stderr);
}, function (err) {
console.err('Command failed with error code of #' + err.status);
});
The actual child process is available if necessary:
var buffspawn('buffered-spawn');
var cp = buffspawn('git', ['clone', 'git@github.com/bower/bower'], function () {}};
var promise = buffspawn('git', ['clone', 'git@github.com/bower/bower']);
var cp = promise.cp;
Tests
$ npm test
License
Released under the MIT License.