简体   繁体   English

nodejs child_process子进程运行两次

[英]nodejs child_process child process run twice

I want to connect a computer by the full computer name on Remote Desktop Connection. 我想通过远程桌面连接上的完整计算机名称连接计算机。 In nodejs, i create a child process to execute a cmd command.It executed successfully,but after two minutes, it execute again. 在nodejs中,我创建了一个子进程来执行cmd命令。它成功执行,但是两分钟后,它再次执行。 I use the kill method of child_process module,it doesn't work. 我使用child_process模块​​的kill方法,它不起作用。

    var child_process = require('child_process');
    child_process.exec('mstsc /v ' + fullName, function(err, stdout, stderr) {
        if(err){
            console.log(err);
        }           
    });
    child_process.kill();

Can you help me? 你能帮助我吗? Thank you very much! 非常感谢你!

Iv'e experienced the same issue, It took me a while to understand, the problem was the HTTP server and not the 'chileProccess'. 我遇到了同样的问题,花了我一段时间才明白,问题出在HTTP服务器,而不是“ chileProccess”。 The missing link in your question is the fact you run the the executeScript through an HTTP request (probably expressJs since you get the timeout after 2 min). 您的问题中缺少的链接是您通过HTTP请求运行executeScript的事实(可能是expressJs,因为您在2分钟后获得超时)。

The problem : since it was not clear. 问题由于不清楚。

What was actually happening is that the HTTP request was reached the timeout boundary set by the HTTP server, which in expressJS is 2 min. 实际发生的情况是HTTP请求达到了HTTP服务器设置的超时边界,在expressJS中为2分钟。

After the timeout, since there was no handling and the request did not closed, it was invoked once more, and so on each 2 min. 超时后,由于没有任何处理且请求没有关闭,因此再次调用了该请求,依此类推,每2分钟一次。

The solution: 解决方案:

server.setTimeout() is the method that sets the HTTP connection timeout for all connections. server.setTimeout()是设置所有连接的HTTP连接超时的方法。

The 2 minutes are default. 默认为2分钟。

Example: 例:

var express = require('express');
var http = require('http');

var app = module.exports.app = express();
var server = http.createServer(app);
server.setTimeout(10*60*1000); // 10 * 60 seconds * 1000 msecs
server.listen(appConfig.port, function () {
    var logger = app.get('logger');
    logger.info('**** STARTING SERVER ****');
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM