buffered-spawn

Buffered child process#spawn.

buffered-spawn

Buffered child_process#spawn.

$ npm install buffered-spawn

  • Easy to use
  • Uses cross-spawn that fixes windows issues
  • Supports callback & promise style

In terms of arguments, they are equal to node's spawn.

var buffspawn = require('buffered-spawn');
 
// Callback style 
buffspawn('git', ['clone', 'git@github.com/bower/bower'], { cwd: '~/foo' }, function (errstdoutstderr) {
    // Both stdout and stderr are set with the buffered output, even on failure 
    if (err) {
        return console.err('Command failed with error code of #'  + err.status);
    }
 
    console.log(stdout);
    console.log(stderr);
});
 
// Promise style 
buffspawn('git', ['clone', 'git@github.com/bower/bower'], { cwd: '~/foo' })
.spread(function (stdoutstderr) {
    console.log(stdout);
    console.log(stderr);
}, function (err) {
    // Besides err.status there's also err.stdout & err.stderr 
    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 (stdoutstderr) {
    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');
 
// Callback style 
var cp = buffspawn('git', ['clone', 'git@github.com/bower/bower'], function () {}};
 
// Promise style 
var promise = buffspawn('git', ['clone', 'git@github.com/bower/bower']);
var cp = promise.cp;

$ npm test

Released under the MIT License.