Using PsExec with spawning a child process results in truncated stdout

孤街浪徒 提交于 2019-12-12 20:25:57

问题


My goal is to be able to execute a command on a remote machine and get the full stdout response from the command that was run. What I am getting is a truncated result. When I run the same command through command prompt, I get the full output from the command run. Here is my code:

    var process    = spawn('PsExec.exe', ['\\\\servername', 'ipconfig']);
    var doOnce = true;
    process.stdout.on('data', function (data) {
        log.info('stdout: ' + data.toString());
        if(doOnce){
            doOnce = false;
            process.stdin.write('ipconfig');}
    });

    process.stderr.on('data', function (data) {
        log.info('stderr: ' + data.toString());
    });

    process.on('exit', function (code) {
        log.info('child process exited with code ' + code);
    });

When executed I get the following console output. As you can tell, all of ipconfig has been truncated. If I do another command such as netstat, I get most of the results before truncating occurs, so I don't believe this has anything to do with the buffer. I really am just out of ideas at this point.

info: stderr: 
PsExec v2.11 - Execute processes remotely
Copyright (C) 2001-2014 Mark Russinovich
Sysinternals - www.sysinternals.com


info: stdout: 
Windows IP Configuration



ipconfig exited on servername with error code 0.

info: child process exited with code 0

回答1:


Try using the { stdio: 'inherit' } option

var spawn = require('child_process').spawn,
appname = spawn('psexec.exe', ['-accepteula', '\\\\remotepcname', '-u', 'domain\\username', '-p', 'supersecretpassword', 'ipconfig'], { stdio: 'inherit' });


来源:https://stackoverflow.com/questions/24395544/using-psexec-with-spawning-a-child-process-results-in-truncated-stdout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!