0

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();
        }
    }

1 Answers1

1

You should try setting CreateNoWindow to true:

process.StartInfo.CreateNoWindow = true;
Adi Lester
  • 24,731
  • 12
  • 95
  • 110
  • FUUUUUUUUUUUUU i thought i tried that. The worse part is i even have `StartInfo.CreateNoWindow = true;` in a different function in the same codefile. But that one doesnt redirect anything. Answer test and accepted! -edit- when it lets me. –  Aug 11 '12 at 20:38