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("执行成功");
        }
    }

 

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