1 | "use strict";
|
2 |
|
3 | const cp = require('child_process');
|
4 | const once = require('../function/once');
|
5 |
|
6 |
|
7 | module.exports = function(cmd /*, options, chain*/) {
|
8 | var args = Array.from(arguments);
|
9 | var chain = once(args.pop());
|
10 | cmd = args.shift();
|
11 | var options = args.shift() || {};
|
12 |
|
13 | if(Array.isArray(options))
|
14 | options = { args : options};
|
15 |
|
16 | options.stdio = ['inherit', 'inherit', 'inherit'];
|
17 |
|
18 | var ps = cp.spawn(cmd, options.args || [], options);
|
19 |
|
20 | ps.on('error', chain);
|
21 |
|
22 | ps.on('close', function(exit) {
|
23 | var err = null;
|
24 | if(exit !== 0)
|
25 | err = "Bad exit code " + exit;
|
26 | return chain(err, exit);
|
27 | });
|
28 | };
|
29 |
|