I am trying to run a shell script from a post request, I want to pass parameter from the post request to this shell script.
const Helpers = use('Helpers')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const shellCommand = Helpers.appRoot('shellCommand.sh')
class someController {
async generate({ request, response }) {
let { VERSION } = request.body
try {
await exec(shellCommand + VERSION, function (error, stdout, stderr) {
if (error !== null) {
console.log(error);
} else {
console.log('stdout: ' + stdout);
console.log('stderr: ' + stderr);
}
})
}
catch (error) {
console.log(error);
}
await response.send(JSON.stringify({ "status": 200, "message": "generate success", "version": version}))
}
}
This is how I tried to get the parameter in my shell command.
VERSION = $1
If I try running the service this is the result I got. It passes the parameter as addition to the file name instead. I know this isn't the correct way to pass parameter to shell script in Adonis JS, I've searched the internet but couldn't find the way to do it. error