Run shell script with node.js (childProcess)

Ralf picture Ralf · Sep 30, 2013 · Viewed 60.9k times · Source

I want to run a shell script on my node.js server, but nothing happened...

childProcess.exec('~/./play.sh /media/external/' + req.params.movie, function() {}); //not working

Another childProcess works perfect, but the process above won't.

childProcess.exec('ls /media/external/', movieCallback); //works

If I run the script in terminal, then it works. Any ideas? (chmod +x is set)

Answer

smokey.edgy picture smokey.edgy · Sep 30, 2013

The exec function callback has error, stdout and stderr arguments passed to it. See if they can help you diagnose the problem by spitting them out to the console:

exec('~/./play.sh /media/external/' + req.params.movie,
  function (error, stdout, stderr) {
    console.log('stdout: ' + stdout);
    console.log('stderr: ' + stderr);
    if (error !== null) {
      console.log('exec error: ' + error);
    }
});