I have th开发者_高级运维is code:
ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
PSI.CreateNoWindow = true;
PSI.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = true;
Process p = Process.Start(PSI);
problem is, when I build it, the command prompt still appears. How can I hide it?Thanks!
In Visual Studio, change the output type under Application in the project properties to Windows Application.
Project Properties > Application > Output Type: "Windows Application"
Also try:
PSI.UseShellExecute = false;
After copy pasting your code, there's an exception that you probably aren't noticing. To redirect the IO streams, the UseShellExecute property must be set to false.
Also, PSI.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
is not required. Here is your working code:
ProcessStartInfo PSI = new ProcessStartInfo("cmd.exe");
PSI.CreateNoWindow = true;
//PSI.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
PSI.RedirectStandardInput = true;
PSI.RedirectStandardOutput = true;
PSI.RedirectStandardError = true;
PSI.UseShellExecute = false;
Process p = Process.Start(PSI);
精彩评论