Ejecutar este archivo JS en el lado del servidor de mi sitio web para que cuando el usuario presione un botón, ejecute este comando con mi API:
exports.runAlgorithm = async (req, res) => { try { exec('java test.java', (error, stdout, stderr) => { if (error) { console.error(`${error}`); return; } try { //Export the result to the database Result.create({ //Should send the algorithm's result here result: stdout }) res.send({ message: "Algorithm executed successfully and output stored in database", }); } catch (err) { res.send({ message: "Something went wrong when passing the data to the database", }); console.log(`stderr: ${stderr}`); } }); } catch (err) { res.send({ message: "Problem with running the algo" }); } }Pero recibo este error:
exec error: Error: Command failed: java test.java Error: Could not find or load main class test.java Caused by: java.lang.ClassNotFoundException: test.javaTambién probé la alternativa execFile pero fue en vano. Tal vez solo lo estoy usando incorrectamente o hay una mejor manera de hacerlo.