unity 調用.exe程序

  windows程序中Debug文件拷貝到unity項目文件下(和Assets文件夾同級),修改Debug文件名再使用代碼調用。

private string savePath = System.Environment.CurrentDirectory+ @"\文件夾名";

public void RunExeByProcess(string arguments)
    {
        //開啓新線程
        System.Diagnostics.Process process = new System.Diagnostics.Process();
        //調用的exe名稱
        process.StartInfo.FileName = "ProjectName";
        process.StartInfo.WorkingDirectory = savePath;
        //傳遞參數
        process.StartInfo.Arguments = arguments;
        process.Start();

        process.WaitForExit();//停頓,當外部程序退出後才能繼續執行

        if (process.ExitCode == 0)//程序退出
        {
            print("執行成功");
        }
    }

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章