节点执行者无权执行脚本 [英] Node exec doesn't have permission to execute script

查看:67
本文介绍了节点执行者无权执行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

直到最近,它仍然可以正常工作,但是当我今天尝试使用它时,它无法正常工作.它返回以下错误:

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:

错误:命令失败:/bin/sh -c/home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js12345678/bin/sh:1:/home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js:权限被拒绝

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

我非常困惑,因为当我尝试从命令行运行脚本时,它可以完美运行;/home/pi/RPi-Computer-Power/RPi-Server/routes/../scripts/hash.js 12345 完美执行.

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.

这是我尝试执行脚本的代码.(index.js)

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

推荐答案

我想到两件事:

1)确保您要执行的脚本是可执行的,例如: chmod + x/folder/script

1) Make sure that the script you are trying to execute is executable ex: chmod +x /folder/script

2)在许多 Linux 发行版中,默认的终端外壳是 bash .您显示的错误包括使用/bin/sh -c ,在许多 Linux 发行版中,默认设置为 dash (是的,不同的默认 shell 用于终端,以及用于在没有终端的情况下运行脚本的代码).因此,由于它似乎可以在 bash 中使用,请尝试使用 bash -c/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.

这篇关于节点执行者无权执行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆