private static string ExecuteCmd(string wrokDirectory, string dosCommand)
{
string output = string.Empty;
if (string.IsNullOrEmpty(wrokDirectory) || string.IsNullOrEmpty(dosCommand))
{
return output;
}
Process process = new Process();
ProcessStartInfo startInfo = new ProcessStartInfo();
startInfo.FileName = "cmd.exe";
//startInfo.Arguments = "/C " + dosCommand; //設定參數,其中的“/C”表示執行完命令后馬上退出
startInfo.UseShellExecute = false; //不使用系統外殼程序啟動
startInfo.RedirectStandardInput = false; //不重定向輸入
startInfo.RedirectStandardOutput = true; //重定向輸出
startInfo.CreateNoWindow = true; //不創建窗口
//startInfo.WorkingDirectory = wrokDirectory;
process.StartInfo = startInfo;
try
{
if (process.Start()) //開始進程
{
process.StandardOutput.ReadToEnd(); //讀取輸出流釋放緩沖, 不加這一句,進程會一直無限等待
process.WaitForExit();
}
}
catch (Exception e)
{
Debug.Log("Exception !!!");
}
return output;
}