开发者

nodejs child_processes.exec can not return 'nohup' command

开发者 https://www.devze.com 2023-02-24 03:52 出处:网络
I write a function of nodejs to execute a \'nohup\' command and send the success result as http response.

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!");
 开发者_JAVA技巧   });
}

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

0

精彩评论

暂无评论...
验证码 换一张
取 消