System.Diagnostics.Process.Start("cmd.exe");第二种方法(静态方法):
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo("cmd.exe");
info.FileName = "cmd.exe";
info.WorkingDirectory = @"C:\";
System.Diagnostics.Process.Start(info);第三种方法(实例方法):
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/C dir";
process.StartInfo.WorkingDirectory = @"C:\";
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.Start();
if(!process.WaitForExit(5000)) process.Kill(); //进程已退出再Kill会出错
Console.WriteLine(process.StandardOutput.ReadToEnd());
评论(0)
暂无评论。