-
Notifications
You must be signed in to change notification settings - Fork 3
/
exec.js
41 lines (33 loc) · 980 Bytes
/
exec.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
let cp = require("child_process");
let args = process.argv.slice(2);
args[0] += (process.platform == "win32")?".bat":".sh";
let prefix = (process.platform == "win32")?"app-scripts\\":"./app-scripts/";
let command = prefix + args.join(" ");
console.log("----------------------------------------");
console.log("exec:", command);
console.log("----------------------------------------", "\n");
// const proc = cp.spawn("ls", ["-lh"]);
const proc = cp.spawn(prefix + args[0], args.slice(1), {cwd: __dirname, env: process.env});
proc.stdout.on("data", (data) => {
console.log(data.toString());
});
proc.stderr.on("data", (data) => {
console.error("error:", data);
});
proc.on("close", (code) => {
if (code != 0)
console.log(`child process exited with code ${code}`);
});
proc.on("error", (e) => {
console.error("error:", e.message);
console.error(e);
});
/*
try {
let stdout = cp.execSync(command).toString();
console.log(stdout);
}
catch(e) {
console.error(e);
}
*/