輸出我跑這個無法從CMD
string path = string.Format(@"\\{0}\c$\Windows\CCM\Logs", computerName);
Process process = Process.Start(new ProcessStartInfo()
{
FileName = "cmd.exe",
Arguments = string.Format(@"net use {0} && dir {0}", path),
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
});
string result = process.StandardOutput.ReadToEnd() + " " + process.StandardError.ReadToEnd();
process.WaitForExit();
Console.WriteLine(result);
但沒有什麼是永遠寫入控制檯。我究竟做錯了什麼?我已經瀏覽過其他所有關於此的SO線程,並做了大量的谷歌搜索,但我無法實現它的工作。
'cmd.exe'在處理完命令後沒有自動關閉,它等待進一步的輸入,所以你的程序停在'process.WaitForExit'而不是'Console.WriteLine(result)'。基於事件監聽或異步輸出的建議解決方案應該可行。 – Fedor