Spaces:
Sleeping
Sleeping
Update index.js
Browse files
index.js
CHANGED
@@ -78,6 +78,31 @@ app.post("/compile", function (req, res) {
|
|
78 |
}
|
79 |
});
|
80 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
}
|
82 |
} catch (e) {
|
83 |
console.log("error:" + e);
|
@@ -87,4 +112,4 @@ app.post("/compile", function (req, res) {
|
|
87 |
const port = 7860;
|
88 |
app.listen(port, () => {
|
89 |
console.log(`Open http://localhost:${port}`);
|
90 |
-
});
|
|
|
78 |
}
|
79 |
});
|
80 |
}
|
81 |
+
}else if(lang == "Java"){
|
82 |
+
fs.writeFile("/code/temp/Main.java", code, (err) => {
|
83 |
+
if (err) {
|
84 |
+
console.error(err);
|
85 |
+
res.status(500).send("Error writing Java file");
|
86 |
+
return;
|
87 |
+
}
|
88 |
+
const javaProcess = exec(
|
89 |
+
"javac -d /code/temp /code/temp/Main.java && java -cp /code/temp Main",
|
90 |
+
(error, stdout, stderr) => {
|
91 |
+
if (error) {
|
92 |
+
console.error(error);
|
93 |
+
res.send({error:stderr});
|
94 |
+
return;
|
95 |
+
}
|
96 |
+
console.log(stdout);
|
97 |
+
console.error(stderr);
|
98 |
+
res.send({output:stdout});
|
99 |
+
}
|
100 |
+
);
|
101 |
+
if (input) {
|
102 |
+
javaProcess.stdin.write(input);
|
103 |
+
javaProcess.stdin.end();
|
104 |
+
}
|
105 |
+
});
|
106 |
}
|
107 |
} catch (e) {
|
108 |
console.log("error:" + e);
|
|
|
112 |
const port = 7860;
|
113 |
app.listen(port, () => {
|
114 |
console.log(`Open http://localhost:${port}`);
|
115 |
+
});
|