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. I use the kill method of child_process module,it doesn't work.
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!
Usually, Node. js allows single-threaded, non-blocking performance but running a single thread in a CPU cannot handle increasing workload hence the child_process module can be used to spawn child processes. The child processes communicate with each other using a built-in messaging system.
spawn returns an object with stdout and stderr streams. You can tap on the stdout stream to read data that the child process sends back to Node. stdout being a stream has the "data", "end", and other events that streams have.
Node. js provides the fork() function, a variation of spawn() , to create a child process that's also a Node. js process. The main benefit of using fork() to create a Node.
You can drop privileges after executing mongod (with process. setuid() and process. setgid() ) if you want.
Iv'e experienced the same issue, It took me a while to understand, the problem was the HTTP server and not the '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).
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.
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.
The solution:
server.setTimeout() is the method that sets the HTTP connection timeout for all connections.
The 2 minutes are default.
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 ****');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With