can anyone tell me how to spawn another console application from a Winforms app, but (A) not show the console window on the screen, and (B) still obtain the standard output of the application? Currently I have something like the following:
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();
If I set RedirectStandardOutput to false, then the console app is hidden as expected, but I cannot get the standard output text. However, as soon as I set the RedirectStandardOutput to true, the window stops being hidden, although I am able to get the program's output.
So, I know how to make the console app run hidden, and I know how to get the program's output, but how do I get it to do both?
Many TIA
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…