0

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?

Nick
  • 49
  • 6

1 Answers1

1

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).

André Laszlo
  • 15,169
  • 3
  • 63
  • 81
  • Thanks, i've tried child.exec() but it can return only 200K max because of buffer capacity. Is it possible to spawn process with sudo? I agree with you about sudo permissions but actually i don't know better way to avoid it. – Nick Jul 28 '15 at 08:35
  • I think you'll have the same problem with execFile? You can use the `maxBuffer` option with `exec`, but maybe you should read from the child so that your buffer is not filled up. See [this](http://stackoverflow.com/a/9781295/98057) for example. – André Laszlo Jul 28 '15 at 08:40
  • You could also [redirect output to a file](https://nodejs.org/api/child_process.html#child_process_child_stdio), – André Laszlo Jul 28 '15 at 08:46