1 | child-process-promise
|
2 | =====================
|
3 |
|
4 | [![Build Status](https://travis-ci.org/patrick-steele-idem/child-process-promise.svg?branch=master)](https://travis-ci.org/patrick-steele-idem/child-process-promise)
|
5 | [![NPM](https://img.shields.io/npm/v/child-process-promise.svg)](https://www.npmjs.com/package/child-process-promise)
|
6 | [![Downloads](https://img.shields.io/npm/dm/child-process-promise.svg)](http://npm-stat.com/charts.html?package=child-process-promise)
|
7 |
|
8 | Simple wrapper around the `child_process` module that makes use of promises
|
9 |
|
10 | # Installation
|
11 | ```
|
12 | npm install child-process-promise --save
|
13 | ```
|
14 |
|
15 | # Usage
|
16 |
|
17 | ## exec
|
18 | ```javascript
|
19 | var exec = require('child-process-promise').exec;
|
20 |
|
21 | exec('echo hello')
|
22 | .then(function (result) {
|
23 | var stdout = result.stdout;
|
24 | var stderr = result.stderr;
|
25 | console.log('stdout: ', stdout);
|
26 | console.log('stderr: ', stderr);
|
27 | })
|
28 | .catch(function (err) {
|
29 | console.error('ERROR: ', err);
|
30 | });
|
31 | ```
|
32 |
|
33 | ## spawn
|
34 | ```javascript
|
35 | var spawn = require('child-process-promise').spawn;
|
36 |
|
37 | var promise = spawn('echo', ['hello']);
|
38 |
|
39 | var childProcess = promise.childProcess;
|
40 |
|
41 | console.log('[spawn] childProcess.pid: ', childProcess.pid);
|
42 | childProcess.stdout.on('data', function (data) {
|
43 | console.log('[spawn] stdout: ', data.toString());
|
44 | });
|
45 | childProcess.stderr.on('data', function (data) {
|
46 | console.log('[spawn] stderr: ', data.toString());
|
47 | });
|
48 |
|
49 | promise.then(function () {
|
50 | console.log('[spawn] done!');
|
51 | })
|
52 | .catch(function (err) {
|
53 | console.error('[spawn] ERROR: ', err);
|
54 | });
|
55 | ```
|
56 | ### Options
|
57 |
|
58 | #### capture
|
59 | Type: `Array`
|
60 | Default: `[]`
|
61 |
|
62 | Pass an additional `capture` option to buffer the result of `stdout` and/or `stderr`
|
63 |
|
64 | ```javascript
|
65 | var spawn = require('child-process-promise').spawn;
|
66 |
|
67 | spawn('echo', ['hello'], { capture: [ 'stdout', 'stderr' ]})
|
68 | .then(function (result) {
|
69 | console.log('[spawn] stdout: ', result.stdout.toString());
|
70 | })
|
71 | .catch(function (err) {
|
72 | console.error('[spawn] stderr: ', err.stderr);
|
73 | });
|
74 | ```
|