forked from bbyars/mountebank
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.js
36 lines (28 loc) · 819 Bytes
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
'use strict';
const spawn = require('child_process').spawn,
os = require('os');
function isWindows () {
return os.platform().indexOf('win') === 0;
}
async function run (command, args, options) {
if (isWindows()) {
// spawn on Windows requires an exe
args.unshift(command);
args.unshift('/c');
command = 'cmd.exe';
}
options.stdio = 'inherit';
console.log(`${command} ${args.join(' ')} with ${JSON.stringify(options)}`);
return new Promise((resolve, reject) => {
const proc = spawn(command, args, options);
proc.on('close', function (exitCode) {
if (exitCode === 0) {
resolve();
}
else {
reject(exitCode);
}
});
});
}
module.exports = { run };