Unity 运行Exe应用程序

2022-07-24  本文已影响0人  CERI_CHANNEL
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;
}
上一篇 下一篇

猜你喜欢

热点阅读