-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexecuteCpp.js
More file actions
30 lines (25 loc) · 752 Bytes
/
executeCpp.js
File metadata and controls
30 lines (25 loc) · 752 Bytes
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
const { exec } = require("child_process");
const fs = require("fs");
const path = require("path");
const { stderr } = require("process");
const outputPath = path.join(__dirname, "outputs");
if (!fs.existsSync(outputPath)) {
fs.mkdirSync(outputPath, { recursive: true });
}
const executeCpp = (filepath) => {
const jobId = path.basename(filepath).split(".")[0];
const outPath = path.join(outputPath, `${jobId}.exe`);
return new Promise((resolve, reject) => {
exec(
`g++ ${filepath} -o ${outPath} && cd ${outputPath} && ${jobId}.exe`,
(error, stdout, stderr) => {
error && reject({ error, stderr });
stderr && reject(stderr);
resolve(stdout)
}
);
});
};
module.exports = {
executeCpp,
};