I wrote the following web server in node.js using express and hbs that can run shell files, but I keep getting the following error when I type this url into a web browser
linux username here is replaced with my linux username
http://127.0.0.1:3000/run?file="/home/linux username here/nasServer/GameServers/minecraft/1.16.2 server/run.sh" stderr: bash: <path to .sh file here>: No such file or directory. child process exited with code 127. Contents of nodejs file:
const express = require('express') const hbs = require('hbs') const app = express() const port = 3000 // Set up handlebars engine app.set('view engine', 'hbs') app.get('/run', (req, res) => { const { spawn } = require('child_process'); let callback = "" ls = spawn("bash", [req.query.file]) ls.stdout.on('data', function (data) { console.log('stdout: ' + data.toString()); }); ls.stderr.on('data', function (data) { console.log('stderr: ' + data.toString()); }); ls.on('close', function (code) { console.log('child process exited with code ' + code.toString()); }); res.send({ out: callback }) }) app.listen(port, () => { console.log(`App listening on port ${port}`) }) This is the contents of run.sh:
#!/bin/bash java -Xmx5G -jar /home/linux username here/nasServer/GameServers/minecraft/1.16.2\ server/spigot-1.16.2.jar nogui