我试图模仿进程内的进程(对于我正在制作的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)
答案 0 :(得分:1)
问题解决了: