i node.js(v10.15.3)我正在尝试使用psexec,它是pstools中的一个exe。从node.js,我想在远程Windows服务器上执行命令;因此使用psexec.exe。
这是我正在使用的代码,
const child_process = require('child_process');
var lineBuffer = "";
var workerProcess = child_process.spawn('cmd', ['/c', 'PsExec \\\\XXX.XXX.XX.XXX -u username -p password typeperf "\\Processor(_Total)\\% Processor Time"']);
workerProcess.stdout.on('data', function (data) {
lineBuffer += data.toString();
console.log('lineBuffer: ' + lineBuffer);
});
workerProcess.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
workerProcess.on('close', function (code) {
console.log('process exited with code ' + code);
});
但是此代码给出了错误,
PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com
Starting typeperf on XXX.XXX.XX.XXX...XXX.XX.XXX...
typeperf exited on XXX.XXX.XX.XXX with error code -268435454.
process exited with code 4026531842
但是当我更改命令时
'PsExec \\\\XXX.XXX.XX.XXX -u username -p password typeperf "\\Processor(_Total)\\% Processor Time"'
到
'PsExec \\\\XXX.XXX.XX.XXX -u username -p password netstat -ano'
这不会给出错误,但会在控制台上显示被截断的输出。
PsExec v2.2 - Execute processes remotely
Copyright (C) 2001-2016 Mark Russinovich
Sysinternals - www.sysinternals.com
Active Connections
Proto Local Address Foreign Address State PID
请提出建议或帮助解决此问题。如果将spawn更改为exec,我很好。数周来,我一直在努力解决这个问题。预先非常感谢。