如何创建SSH克隆?

问题描述 投票:0回答:1

我试图模仿进程内的进程(对于我正在制作的ssh克隆)。它有效,但与cmd.exe本身(see picture)相比并不是很好。正如您在图片中看到的那样,模拟过程回应命令(箭头指向),有时拒绝打印任何内容(带圆圈的正确响应)。

var startInfo   = new ProcessStartInfo("cmd") {
CreateNoWindow  = true,
UseShellExecute = false,
RedirectStandardError   = true,
RedirectStandardInput   = true,
RedirectStandardOutput  = true
};
var shell = new Process() {
    StartInfo = startInfo
};

new Thread(() => {
    char[] buffer = new char[512];
    int read;
    while(true) {
        if((read = shell.StandardOutput.Read(buffer, 0, 512)) > 0) {
            Console.Out.Write(buffer, 0, read);
    }
}).Start();
while(true) {
    shell.StandardInput.WriteLine(Console.ReadLine());
}
shell.WaitForExit();

我究竟做错了什么?

编辑:我试过调整代码页(参见here

c# cmd console
1个回答
1
投票

问题解决了:

  • 省略的错误消息被写入标准错误流,我没有阅读。
  • “echoed”命令只是显示其输入的shell;例如,如果我写“type /?”,shell将显示“... \ Debug> type /?”,从标准输出中读取并回显。
© www.soinside.com 2019 - 2024. All rights reserved.