using System.Collections; using System.Collections.Generic; using UnityEngine; public class SystemCMD { /// /// 调用终端执行命令 /// /// /// public static string RunCmd(string command) { System.Diagnostics.Process p = new System.Diagnostics.Process(); p.StartInfo.FileName = "cmd.exe"; //确定程序名 p.StartInfo.Arguments = "/c " + command; //确定程式命令行 p.StartInfo.UseShellExecute = false; //Shell的使用 p.StartInfo.RedirectStandardInput = true; //重定向输入 p.StartInfo.RedirectStandardOutput = true; //重定向输出 p.StartInfo.RedirectStandardError = true; //重定向输出错误 p.StartInfo.CreateNoWindow = true; //设置置不显示示窗口 p.Start(); p.WaitForExit(); string err = p.StandardError.ReadToEnd(); string standoutput = p.StandardOutput.ReadToEnd(); if (string.IsNullOrEmpty(err)) { return standoutput; } else { return err; //输出出流取得命令行结果果 } } }