C#: Run external console program as hidden

前端 未结 2 1898
我寻月下人不归
我寻月下人不归 2020-12-18 21:19

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

相关标签:
2条回答
  • 2020-12-18 21:54

    I think it will help you:

    System.Diagnostics.Process pProcess = new System.Diagnostics.Process();
    pProcess.StartInfo.FileName = @"C:\Users\Vitor\ConsoleApplication1.exe";
    pProcess.StartInfo.Arguments = "olaa"; //argument
    pProcess.StartInfo.UseShellExecute = false;
    pProcess.StartInfo.RedirectStandardOutput = true;
    pProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
    pProcess.StartInfo.CreateNoWindow = true; //not diplay a windows
    pProcess.Start();
    string output = pProcess.StandardOutput.ReadToEnd(); //The output result
    pProcess.WaitForExit();
    
    0 讨论(0)
  • 2020-12-18 21:55

    You are missing the CreateNoWindow property which has to be set to true in your case.

    0 讨论(0)
提交回复
热议问题