Spaces:
Sleeping
Sleeping
Update index.js
Browse files
index.js
CHANGED
|
@@ -69,6 +69,32 @@ app.post("/compile", function (req, res) {
|
|
| 69 |
}
|
| 70 |
});
|
| 71 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
} catch (e) {
|
| 73 |
console.log("error:" + e);
|
| 74 |
}
|
|
|
|
| 69 |
}
|
| 70 |
});
|
| 71 |
}
|
| 72 |
+
else if (lang == "C++") {
|
| 73 |
+
fs.writeFile("/code/temp/Main.cpp", code, (err) => {
|
| 74 |
+
if (err) {
|
| 75 |
+
console.error(err);
|
| 76 |
+
res.status(500).send("Error writing C++ file");
|
| 77 |
+
return;
|
| 78 |
+
}
|
| 79 |
+
const cppProcess = exec(
|
| 80 |
+
"g++ -o /code/temp/Main /code/temp/Main.cpp && /code/temp/Main",
|
| 81 |
+
(error, stdout, stderr) => {
|
| 82 |
+
if (error) {
|
| 83 |
+
console.error(error);
|
| 84 |
+
res.send({ error: stderr });
|
| 85 |
+
return;
|
| 86 |
+
}
|
| 87 |
+
console.log(stdout);
|
| 88 |
+
console.error(stderr);
|
| 89 |
+
res.send({ output: stdout });
|
| 90 |
+
}
|
| 91 |
+
);
|
| 92 |
+
if (input) {
|
| 93 |
+
cppProcess.stdin.write(input);
|
| 94 |
+
cppProcess.stdin.end();
|
| 95 |
+
}
|
| 96 |
+
});
|
| 97 |
+
}
|
| 98 |
} catch (e) {
|
| 99 |
console.log("error:" + e);
|
| 100 |
}
|