如何使用nodejs调用Windows进程

时间:2019-07-04 10:20:45

标签: javascript node.js express windows-services

我的机器上的端口8123上有一个进程正在运行,如何使用nodejs调用或调用Windows进程??

我尝试使用request

let bytes = new Buffer(xml, 'ascii')
var options = {
    url: "https://" + host + ":" + port,
    headers: {
        'Content-Type': 'text/xml',
        'Content-Length': Buffer.byteLength(bytes),
        'Connection': 'keep-alive'
    },
    method: 'POST',
    requestCert: true,
    agent: false,
    rejectUnauthorized: false
};

function callback(error, response, body) {
    if (error) cb(error)
    else cb(response)
}
request(options, callback);

,但返回的错误代码为ECONNRESET,消息为socket hang up

也这样尝试过HTTP

var options = {
    host: '127.0.0.1',
    port: port,
    method: 'POST',
    agent: false,
    headers: {
        'Content-Length': Buffer.byteLength(bytes),
        'Content-Type': 'text/xml',
        'Connection': 'keep-alive'
    },
};
var req = http.request(options, function (res) {
    res.on('data', function (chunk) {
        cb('BODY: ' + chunk);
    });
});
req.on('error', function (e) {
    cb('problem with request: ' + e.message);
});
req.end();

这也会返回相同的错误

0 个答案:

没有答案