[C#] C#不打开Dos窗口运行控制台程序 →→→→→进入此内容的聊天室

来自 , 2021-01-28, 写在 C#, 查看 139 次.
URL http://www.code666.cn/view/a787f02e
  1. // This snippet needs the "System.Diagnostics"
  2. // library
  3.  
  4. // Application path and command line arguments
  5. string ApplicationPath = "C:\\example.exe";
  6. string ApplicationArguments = "-c -x";
  7.  
  8. // Create a new process object
  9. Process ProcessObj = new Process();
  10.  
  11. // StartInfo contains the startup information of
  12. // the new process
  13. ProcessObj.StartInfo.FileName = ApplicationPath;
  14. ProcessObj.StartInfo.Arguments = ApplicationArguments;
  15.  
  16. // These two optional flags ensure that no DOS window
  17. // appears
  18. ProcessObj.StartInfo.UseShellExecute = false;
  19. ProcessObj.StartInfo.CreateNoWindow = true;
  20.  
  21. // If this option is set the DOS window appears again :-/
  22. // ProcessObj.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
  23.  
  24. // This ensures that you get the output from the DOS application
  25. ProcessObj.StartInfo.RedirectStandardOutput = true;
  26.  
  27. // Start the process
  28. ProcessObj.Start();
  29.  
  30. // Wait that the process exits
  31. ProcessObj.WaitForExit();
  32.  
  33. // Now read the output of the DOS application
  34. string Result = ProcessObj.StandardOutput.ReadToEnd();
  35. //csharp/2104

回复 "C#不打开Dos窗口运行控制台程序"

这儿你可以回复上面这条便签

captcha