>在C#應用程序中捕獲命令行輸出
> 在C#開發中,您通常需要運行命令行應用程序並檢索其輸出。這對於諸如文件比較之類的任務至關重要(使用之類的工具)。 diff
類提供了強大的解決方案。這是逐步指南:Process
啟動外部進程:
Process process = new Process();
>
process.StartInfo.UseShellExecute = false; process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.FileName = "YOURBATCHFILE.bat"; // Or any executable path
process.Start();
string output = process.StandardOutput.ReadToEnd();
字符串變量現在將保留命令的標準輸出。
process.WaitForExit();
以上是如何在C#中檢索命令行輸出?的詳細內容。更多資訊請關注PHP中文網其他相關文章!