美文网首页
Unity 运行Exe应用程序

Unity 运行Exe应用程序

作者: CERI_CHANNEL | 来源:发表于2022-07-24 09:42 被阅读0次
    private static int ExecuteBat(string path, string arg)
    {
        int code = 0;
        System.Diagnostics.Process proc = null;
        var currentWorkDirectory Directory.GetCurrentDirectory();
        try
        {
            Directory.SetCurrentDirectory(Path.GetDirectoName(path));
            proc = new System.Diagnostics.Process();
            if (Application.platform == RuntimePlatform.WindowsEditor || Application.platform == RuntimePlatform.WindowsPlayer)
            {
                proc.StartInfo.FileName = path;
                proc.StartInfo.Arguments = arg;
            }
            else
            {
                proc.StartInfo.FileName = "/bin/bash";
                proc.StartInfo.Arguments = path + " " arg;
            }
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = true;
            proc.StartInfo.RedirectStandardError = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.Start();
            proc.WaitForExit();
            code = proc.ExitCode;
            proc.Close();
            return code;
        }
        catch (Exception ex)
        {
            Debug.LogException(ex);
        }
        finally
        {
            Directory.SetCurrentDirectory(currentWorkDireory);
        }
        return 1;
    }
    

    相关文章

      网友评论

          本文标题:Unity 运行Exe应用程序

          本文链接:https://www.haomeiwen.com/subject/bfrgirtx.html