Reputation:
Here is some real code you can run. When you do this you'll notice 5 console windows quickly pop up and disappear.
How do i redirect stdout/err without making these windows pop up? I tried a few things and failed so far. For my actual use i'll need arguements and redirect stdin but that shouldn't affect the solution.
[STAThread]
static void Main()
{
for(int i=0;i<5;i++)
{
var process = new System.Diagnostics.Process();
process.StartInfo.FileName = @"C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe";
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; //doesnt seem to have an effect
process.Start();
process.WaitForExit();
var resO = process.StandardOutput.ReadToEnd();
var resE = process.StandardError.ReadToEnd();
}
}
Upvotes: 0
Views: 84
Reputation: 25211
You should try setting CreateNoWindow
to true
:
process.StartInfo.CreateNoWindow = true;
Upvotes: 1