我有以下代码。cmd.exe进程永不完成
ProcessStartInfo si = new ProcessStartInfo("cmd.exe");
si.RedirectStandardInput = true;
si.RedirectStandardOutput = true;
si.UseShellExecute = false;
si.WindowStyle = ProcessWindowStyle.Hidden;
si.CreateNoWindow = true;
Process p = Process.Start(si);
p.StandardInput.Write("ipconfig");
p.StandardInput.Write("exit");
string consoleOutput = p.StandardOutput.ReadToEnd();
string dir="here";
执行到达“字符串consoleOutput”,但从来没有达到“字符串目录”,即代码卡上读取StandardOutput。它在控制台应用程序中运行,如果这有所作为。
如果您已经从控制台应用程序运行,为什么不直接调用'ipconfig'而不是不必要地产生'cmd'? – Petesh
我可以用console.write来做这个吗? – coolblue2000
console.write实际上不会启动该进程,它是启动它的'Process.Start(si)'。 – Petesh