-
Notifications
You must be signed in to change notification settings - Fork 0
/
command-line.js
43 lines (37 loc) · 1.12 KB
/
command-line.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
const { spawnSync } = require("child_process");
const { getStatusObject } = require("./util");
const { checkSignalTermination } = require("./util");
// see nodejs docx for params for spawnSync
const execute = (command, args_arr, options) => {
//modify as per need
const pc_status = {
output: "",
memory: "",
error: false,
error_msg: "",
input_file_path: "",
object_file_path: "", //[c,c++]
time: 0
};
const start_time = new Date();
const pc = spawnSync(command, args_arr, options);
const end_time = new Date();
//process exit code
if (pc.status && pc.status != 0) {
pc_status.error = true;
pc_status.error_msg = pc.stderr.toString();
return pc_status;
}
//see if terminated by signal
const signal_termination = checkSignalTermination(pc.signal);
if (signal_termination) {
pc_status.error = true;
pc_status.error_msg = signal_termination.error_msg;
return pc_status;
}
// NO errors
pc_status.output = pc.stdout ? pc.stdout.toString() : "";
pc_status.time = (end_time.getTime() - start_time.getTime()) / 1000;
return pc_status;
};
module.exports = { execute };