buffered-spawn outside of NSA/Microsoft Github/npm
  • JavaScript 100%
Find a file
2017-06-06 14:37:24 +01:00
test io -> output. 2016-09-15 00:44:35 +01:00
.editorconfig Update .editorconfig (made with screpto) 2016-01-02 15:12:49 +00:00
.eslintrc.json Make it only work on node > 4.0.0, update eslint config. 2016-02-20 22:34:51 +00:00
.gitignore Initial commit. 2014-06-29 11:04:07 +01:00
.travis.yml Make it only work on node > 4.0.0, update eslint config. 2016-02-20 22:34:51 +00:00
index.js Oops. 2016-09-15 00:51:46 +01:00
LICENSE Some love. 2016-01-02 16:39:32 +00:00
package.json chore(package): update cross-spawn to version 5.0.0 2016-10-30 16:36:36 +00:00
README.md Update README.md 2017-06-06 14:37:24 +01:00

buffered-spawn

NPM version Downloads Build Status Dependency status Dev Dependency status Greenkeeper badge

Buffered child_process#spawn.

Installation

$ npm install buffered-spawn

Why

  • Easy to use
  • Uses cross-spawn by default, which fixes windows issues
  • Supports callback & promise style

Usage

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

const bufferedSpawn = require('buffered-spawn');

// Callback style
bufferedSpawn('git', ['clone', 'git@github.com/bower/bower'], { cwd: '.' }, (err, stdout, stderr) => {
    if (err) {
        // Both stdout and stderr are also set on the error object
        return console.error(`Command failed with error code of #${err.status}`);
    }

    console.log(stdout);
    console.log(stderr);
});

// ...or Promise style
bufferedSpawn('git', ['clone', 'git@github.com/bower/bower'], { cwd: '.' })
.then((output) => {
    console.log(output.stdout);
    console.log(output.stderr);
}, (err) => {
    // Both stdout and stderr are also set on the error object
    console.error(`Command failed with error code of #${err.status}`);
});

The actual child process is available if necessary:

const buffspawn('buffered-spawn');

// Callback style
const cp = buffspawn('git', ['clone', 'git@github.com/bower/bower'], () => {}};

// ...or Promise style
const promise = buffspawn('git', ['clone', 'git@github.com/bower/bower']);
const cp = promise.cp;

As said before, buffered-spawn uses cross-spawn to actually spawn the process. If you are having trouble running Windows such as wmic which has its own arguments parser, you may disable like so:

const cp = buffspawn('wmic', [
    'logicaldisk', 'where', 'DeviceID="Z:"',
    'get' 'freeSpace,size'
], { crossSpawn: false }, () => {}};

Tests

$ npm test

License

Released under the MIT License.