如何创建SSH克隆?

时间:2017-12-25 19:04:21

标签: c# cmd console

我试图模仿进程内的进程(对于我正在制作的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

1 个答案:

答案 0 :(得分:1)

问题解决了:

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