问题描述:

I'm trying to get data from python script at Node.js server.

I need to launch this python script with superuser privileges.

child.execFile('sudo python /home/pi/node.js_scripts/app/request.py', function (err, stdout, stderr) {

if (err) throw err;

if (stderr) throw err;

console.log(stdout); });

But i get this error:

Error: spawn sudo python /home/pi/node.js_scripts/app/request.py ENOENT

at exports._errnoException (util.js:746:11)

at Process.ChildProcess._handle.onexit (child_process.js:1046:32)

at child_process.js:1137:20

at process._tickCallback (node.js:355:11)

How can I solve my problem?

网友答案:

The problem is that execFile takes a path to a file. This file needs to be executable. In your case, you're trying to execute a command. Try child.exec() instead, or create a small executable shell script that runs this command.

Also, giving your node.js server sudo permissions is not wise. I don't have any good advice on how to solve that problem though. Maybe look into setuid. It really depends on your use-case (and should be a separate question).

相关阅读:
Top