admin管理员组文章数量:1308161
Up until recently, it has worked fine, but when I tried to use it today, it did not work properly. It returns the following error:
Error: Command failed: /bin/sh -c /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js 12345678 /bin/sh: 1: /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js: Permission denied
I am extremely confused because when I try to run the script from the mand line, it works perfectly; /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js 12345
executes flawlessly.
This is the code where I try to execute the script. (index.js)
exec(__dirname+"/../scripts/"+req.params.script+" "+req.body.params, function(err, stdout, stderr) {
console.log("err: ",err,"stdout: ",stdout,"stderr: ",stderr);
if(err){
res.send("<a href='/'>< Back</a> <b>Program Error:</b> "+err.toString());
return;
}
//res.send("<a href='/'>< Back</a> <b>Program Output:</b> <div style='white-space:pre-line>'"+stdout+stderr+"</div>");
res.render("programOutput", {output: stdout});
});
If anyone has any help, thank you in advance. Neil
Up until recently, it has worked fine, but when I tried to use it today, it did not work properly. It returns the following error:
Error: Command failed: /bin/sh -c /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js 12345678 /bin/sh: 1: /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js: Permission denied
I am extremely confused because when I try to run the script from the mand line, it works perfectly; /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js 12345
executes flawlessly.
This is the code where I try to execute the script. (index.js)
exec(__dirname+"/../scripts/"+req.params.script+" "+req.body.params, function(err, stdout, stderr) {
console.log("err: ",err,"stdout: ",stdout,"stderr: ",stderr);
if(err){
res.send("<a href='/'>< Back</a> <b>Program Error:</b> "+err.toString());
return;
}
//res.send("<a href='/'>< Back</a> <b>Program Output:</b> <div style='white-space:pre-line>'"+stdout+stderr+"</div>");
res.render("programOutput", {output: stdout});
});
If anyone has any help, thank you in advance. Neil
Share Improve this question asked May 5, 2017 at 23:34 ifconfigifconfig 6,87210 gold badges47 silver badges68 bronze badges 1- How are you running node.js? What permissions does it have? – jfriend00 Commented May 6, 2017 at 0:51
1 Answer
Reset to default 7Two things e to mind:
1) Make sure that the script you are trying to execute is executable ex: chmod +x /folder/script
2) The default terminal shell on many Linux
distributions is bash
. The error you displayed includes using /bin/sh -c
, which would default in many Linux
distributions to dash
(yes, a different default shell
for the terminal and for running scripts without the terminal). Thus, since it seems to work in bash
, try to evoke the script with bash -c /folder/script
.
本文标签: javascriptNode exec doesn39t have permission to execute scriptStack Overflow
版权声明:本文标题:javascript - Node exec doesn't have permission to execute script - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741820888a2399357.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论