-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecuteCpp.js
More file actions
37 lines (29 loc) · 916 Bytes
/
Copy pathexecuteCpp.js
File metadata and controls
37 lines (29 loc) · 916 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
31
32
33
34
35
36
37
import {exec} from "child_process"
import path from "path"
import fs from "fs"
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
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)=>{
if(error){
reject({error,stderr});
}
if(stderr){
reject(stderr);
}
resolve(stdout);
})
});
}
export default executeCpp