1 | 'use strict';
|
2 | var spawn = require('child_process').spawn;
|
3 | var executable = require('executable');
|
4 |
|
5 | module.exports = function (bin, cmd, cb) {
|
6 | if (typeof cmd === 'function') {
|
7 | cb = cmd;
|
8 | cmd = ['--help'];
|
9 | }
|
10 |
|
11 | executable(bin, function (err, works) {
|
12 | if (err) {
|
13 | cb(err);
|
14 | return;
|
15 | }
|
16 |
|
17 | if (!works) {
|
18 | cb(new Error('Couldn\'t execute the `' + bin + '` binary. Make sure it has the right permissions.'));
|
19 | return;
|
20 | }
|
21 |
|
22 | var cp = spawn(bin, cmd);
|
23 |
|
24 | cp.on('error', cb);
|
25 | cp.on('exit', function (code) {
|
26 | cb(null, code === 0);
|
27 | });
|
28 | });
|
29 | };
|