I write a function of nodejs to execute a 'nohup' command and send the success result as 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 by the url address, the response data can not return.
child_process.exec()
waits for the child process to exit and then invokes the callback. In your case, you've spawned a background process, which presumably isn't ever exiting.
You probably want child_process.spawn()
:
http://nodejs.org/docs/v0.4.9/api/child_processes.html#child_process.spawn
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.