1
私は小さなコンソールアプリケーションを持っており、C#の出力を読みたいと思います。したがって、このコードスニペットを作成しました。コマンドプロンプトが開きますが、何も表示されません。System.Diagnostic.Processのデッドロック
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal;
process.StartInfo.FileName = DirectoryPath + "Test.exe";
process.StartInfo.Arguments = "-showAll";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.Start();
process.WaitForExit(2000);
String strOutput = process.StandardOutput.ReadToEnd();
私はUseShellExecute
、RedirectStandardOutput
と最後の行を削除する場合は、コマンドプロンプトを開き、Test.exe
が示されているが、私は文字列として出力を必要とするので、私はStandardOutput
また、2秒(process.WaitForExit(2000)
)のタイムアウトを設定しようとしましたが、空のコマンドプロンプトは2秒後に閉じません。
デバッグモードで空のコマンドプロンプトを手動で閉じると、変数strOutputに要求された情報があります。