Question

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();
        }
    }
Was it helpful?

Solution

You should try setting CreateNoWindow to true:

process.StartInfo.CreateNoWindow = true;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top