-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspawn.js
60 lines (43 loc) · 1.42 KB
/
spawn.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
'use strict';
var child_process = require('child_process');
var path = require("path");
var env = Object.assign({}, process.env);
var SEPARATOR = process.platform === "win32" ? ";" : ":";
env.PATH = path.resolve("./node_modules/.bin") + SEPARATOR + env.PATH;
exports.sync = function(cmd, args, opts) {
opts = opts || {};
opts.stdio = 'inherit';
opts.env = env;
if(process.platform === 'win32') {
args = ['/c', cmd].concat(args);
cmd = process.env.comspec;
}
var child = child_process.spawnSync(cmd, args, opts);
// console.log("child.output: " + child.output);
// console.log("child.stdout: " + child.stdout);
// child.output && console.log("child.output: " + child.output);
// child.stdout && console.log("child.stdout: " + child.stdout);
// console.error("child.stderr: " + child.stderr);
// // console.log("child.status: " + child.status);
// child.error && console.log("child.error: " + child.error);
}
exports.async = function(cmd, args, opts) {
return new Promise(function(resolve, reject) {
opts = opts || {};
opts.stdio = 'inherit';
opts.env = env;
if(process.platform === 'win32') {
args = ['/c', cmd].concat(args);
cmd = process.env.comspec;
}
var child = child_process.spawn(cmd, args, opts);
child.on('close', function(code, signal) {
// console.log("npm closed: " + code);
// console.log("npm signal: " + signal);
resolve({
code: code,
signal: signal
});
});
});
}