Jam*_*sPD 14 c# console process
任何人都可以告诉我如何从Winforms应用程序生成另一个控制台应用程序,但(A)没有在屏幕上显示控制台窗口,(B)仍然获得应用程序的标准输出?目前我有以下内容:
Process SomeProgram = new Process();
SomeProgram.StartInfo.FileName = @"c:\foo.exe";
SomeProgram.StartInfo.Arguments = "bar";
SomeProgram.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
SomeProgram.StartInfo.UseShellExecute = false;
SomeProgram.StartInfo.RedirectStandardOutput = true;
SomeProgram.Start();
SomeProgram.WaitForExit();
string SomeProgramOutput = SomeProgram.StandardOutput.ReadToEnd();
Run Code Online (Sandbox Code Playgroud)
如果我将RedirectStandardOutput设置为false,则控制台应用程序将按预期隐藏,但我无法获得标准输出文本.但是,只要我将RedirectStandardOutput设置为true,窗口就会停止隐藏,尽管我能够获得程序的输出.
所以,我知道如何让控制台应用程序运行隐藏,我知道如何获得程序的输出,但我如何让它同时执行?
很多TIA
Ste*_*tze 34
您缺少CreateNoWindow属性,在您的情况下必须将其设置为true.