解決策:
属性を使用して、コンソールアプリケーションの出力を.NETアプリケーションのフローにリダイレクトします。実装:
次のC#コードフラグメントは、コンソールアプリケーションを呼び出してその出力をキャプチャする方法を示しています。
ProcessStartInfo.RedirectStandardOutput
実行可能な実行可能ファイルに関するストレージ情報。
set および
属性を設定して、呼び出されるコンソールアプリケーションを指定します。<code class="language-csharp">Process compiler = new Process(); compiler.StartInfo.FileName = "csc.exe"; compiler.StartInfo.Arguments = "/r:System.dll /out:sample.exe stdstr.cs"; compiler.StartInfo.UseShellExecute = false; compiler.StartInfo.RedirectStandardOutput = true; compiler.Start(); string output = compiler.StandardOutput.ReadToEnd(); Console.WriteLine(output); compiler.WaitForExit();</code>
プロセスをより適切に制御するために無効にします。
現在のプロセスでコンソールの標準出力をコンソールの標準出力を有効にします。ProcessStartInfo
FileName
実行を続ける前に、コンソールアプリケーションが実行を完了するのを待っています。 Arguments
以上がC#で.NETアプリケーションからリアルタイムコンソール出力をキャプチャする方法は?の詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。