Skip to content
Simple wrapper around the "child_process" module that makes use of promises
Branch: master
Clone or download
patrick-steele-idem Merge pull request #31 from olivierto/master
Implemented ChildprocessError class to be conform to Promises/A+ spec
Latest commit 217609b Mar 29, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib Implemented childprocess error to conform to Promises/A+ spec Mar 28, 2017
test
.eslintrc Add `eslint` + minimal config Dec 18, 2014
.gitignore
.jshintrc Fixed test for Node.js 0.10 Aug 12, 2016
.travis.yml Now compatible with all versions of Node.js Aug 12, 2016
CHANGELOG.md
LICENSE Fixes #25 - Added MIT license file Aug 19, 2016
README.md
index.js Now compatible with all versions of Node.js Aug 12, 2016
package.json

README.md

child-process-promise

Build Status NPM Downloads

Simple wrapper around the child_process module that makes use of promises

Installation

npm install child-process-promise --save

Usage

exec

var exec = require('child-process-promise').exec;

exec('echo hello')
    .then(function (result) {
        var stdout = result.stdout;
        var stderr = result.stderr;
        console.log('stdout: ', stdout);
        console.log('stderr: ', stderr);
    })
    .catch(function (err) {
        console.error('ERROR: ', err);
    });

spawn

var spawn = require('child-process-promise').spawn;

var promise = spawn('echo', ['hello']);

var childProcess = promise.childProcess;

console.log('[spawn] childProcess.pid: ', childProcess.pid);
childProcess.stdout.on('data', function (data) {
    console.log('[spawn] stdout: ', data.toString());
});
childProcess.stderr.on('data', function (data) {
    console.log('[spawn] stderr: ', data.toString());
});

promise.then(function () {
        console.log('[spawn] done!');
    })
    .catch(function (err) {
        console.error('[spawn] ERROR: ', err);
    });

Options

capture

Type: Array
Default: []

Pass an additional capture option to buffer the result of stdout and/or stderr

var spawn = require('child-process-promise').spawn;

spawn('echo', ['hello'], { capture: [ 'stdout', 'stderr' ]})
    .then(function (result) {
        console.log('[spawn] stdout: ', result.stdout.toString());
    })
    .catch(function (err) {
        console.error('[spawn] stderr: ', err.stderr);
    });
You can’t perform that action at this time.