Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

child-process-promise

Simple wrapper around the "child_process" module that makes use of promises

child, process, promises

readme

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);
    });

changelog

Changelog

2.x

2.1.x

2.1.0

  • Now compatible with all versions of Node.js (PR #22 by @olsonpm with modification)

2.0.x

2.0.1

  • Minor cleanup

2.0.0

Major changes

  • Switched from q to native ES2015 promises.
  • This module now uses various ES2015 functionality only available in Node.js 4.0+
  • Despite the major version being incremented, v2.x maintains backwards compatibility with v1.x

Breaking changes

  • This library now requires Node.js 4.0+
    • If you are using Node.js <4 you should use child-process-promise@^1.0.0

1.x

  • Initial release