/// <summary> /// 执行CMD语句 /// </summary> /// <param name="cmd">要执行的CMD命令</param> public string RunCmd(string cmd) { proc.StartInfo.CreateNoWindow = true; proc.StartInfo.FileName = "cmd.exe"; proc.StartInfo.UseShellExecute = false; proc.StartInfo.RedirectStandardError = true; proc.StartInfo.RedirectStandardInput = true; proc.StartInfo.RedirectStandardOutput = true; proc.Start(); proc.StandardInput.WriteLine(cmd); proc.StandardInput.WriteLine("exit"); string outStr = proc.StandardOutput.ReadToEnd(); proc.Close(); return outStr; }
时间: 2024-10-17 05:45:42