Nodejs child_processes.exec cannot return nohup command

I am writing a nodejs function to execute the nohup command and sending the success result as an HTTP response.

function _nohup(cmd,res){ var child = exec('nohup ./' + cmd + '.sh &', function (error, stdout, stderr) { res.writeHeader(200); res.end("start process success!"); }); } 

But when I call the function at url, the response data cannot return.

0
source share
1 answer

child_process.exec() waits until the child process child_process.exec() , and then calls the callback. In your case, you created a background process that apparently never leaves.

You probably want child_process.spawn() :

http://nodejs.org/docs/v0.4.9/api/child_processes.html#child_process.spawn

+6
source

All Articles