[英]Node exec doesn't have permission to execute script
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
错误:命令失败:/ 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:权限被拒绝
I am extremely confused because when I try to run the script from the command line, it works perfectly; 我非常困惑,因为当我尝试从命令行运行脚本时,它可以完美运行。
/home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js 12345
executes flawlessly. /home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js 12345
可以完美执行。
This is the code where I try to execute the script. 这是我尝试执行脚本的代码。 (index.js)
(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
尼尔
Two things come to mind: 我想到两件事:
1) Make sure that the script you are trying to execute is executable ex: chmod +x /folder/script
1)确保您尝试执行的脚本是可执行文件,例如:
chmod +x /folder/script
2) The default terminal shell on many Linux
distributions is bash
. 2)在许多
Linux
发行版中,默认的终端外壳是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). 您显示的错误包括使用
/bin/sh -c
,在许多Linux
发行版中,默认情况是- dash
(是的,终端和不具有终端的运行脚本使用不同的默认shell
)。 Thus, since it seems to work in bash
, try to evoke the script with bash -c /folder/script
. 因此,由于它似乎可以在
bash
工作,因此请尝试使用bash -c /folder/script
调用bash -c /folder/script
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.