方法: C# でコマンド ラインを実行し、STD OUT 結果を取得する 質問する

方法: C# でコマンド ラインを実行し、STD OUT 結果を取得する 質問する

C# からコマンド ライン プログラムを実行し、STD OUT の結果を取得するにはどうすればよいですか? 具体的には、プログラムで選択された 2 つのファイルに対して DIFF を実行し、その結果をテキスト ボックスに書き込みます。

ベストアンサー1

// Start the child process.
 Process p = new Process();
 // Redirect the output stream of the child process.
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;
 p.StartInfo.FileName = "YOURBATCHFILE.bat";
 p.Start();
 // Do not wait for the child process to exit before
 // reading to the end of its redirected stream.
 // p.WaitForExit();
 // Read the output stream first and then wait.
 string output = p.StandardOutput.ReadToEnd();
 p.WaitForExit();

コードはマイクロソフト

おすすめ記事