Run shell script with node.js (childProcess)

Solution 1:

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);
    }
});

Solution 2:

exec('sh ~/play.sh /media/external/' + req.params.movie ,function(err,stdout,stderr){
      console.log(err,stdout,stderr);
 })

Runs your play.sh shellscript with /media/external/+req.params.movie as argument. The output is available through stdout,stderr variables in the callback.

OR TRY THIS

var myscript = exec('sh ~/play.sh /media/external/' + req.params.movie);
myscript.stdout.on('data',function(data){
    console.log(data); // process output will be displayed here
});
myscript.stderr.on('data',function(data){
    console.log(data); // process error output will be displayed here
});`