.exe 文件在 运行 从 Unity 到手动打开时表现不同
.exe file behaves differently when run from Unity to when open manually
我正在尝试 运行 来自 Unity 的 .exe。 .exe 运行 当我通过双击手动打开它时完美,但从 Unity 中,它只是打开然后根本不起作用。
.exe 是一个非常基本的 python 脚本(我制作成可执行文件),它读取一个文本文件然后创建另一个文件。当来自 Unity 的 运行 可执行文件 window 说这个文件没有 exist/can 找不到,当我知道它时,然后立即关闭。
我已经尝试 运行使用这些方法安装此 .exe:
Application.OpenURL(path);
并且:
Process.Start(path);
当我点击 .exe 时,它工作得非常好,除了那个文本文件之外没有依赖项或任何其他东西。
如何从代码中 运行 这个文件,就好像它刚刚被点击过一样?
process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = path;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.ErrorDialog = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.EnableRaisingEvents = true;
process.Start();
但我认为您的路径无效。你能 Debug.Log 它并在评论中写下它是什么吗?它应该是绝对路径 btw
解决方案是像这样定义进程的目录:
Process p = new Process();
p.StartInfo.FileName = path + "app.exe";
p.StartInfo.WorkingDirectory = path;
p.Start();
其中 path
是 app.exe 所在文件夹的路径。
我正在尝试 运行 来自 Unity 的 .exe。 .exe 运行 当我通过双击手动打开它时完美,但从 Unity 中,它只是打开然后根本不起作用。
.exe 是一个非常基本的 python 脚本(我制作成可执行文件),它读取一个文本文件然后创建另一个文件。当来自 Unity 的 运行 可执行文件 window 说这个文件没有 exist/can 找不到,当我知道它时,然后立即关闭。
我已经尝试 运行使用这些方法安装此 .exe:
Application.OpenURL(path);
并且:
Process.Start(path);
当我点击 .exe 时,它工作得非常好,除了那个文本文件之外没有依赖项或任何其他东西。
如何从代码中 运行 这个文件,就好像它刚刚被点击过一样?
process = new Process();
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = path;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.ErrorDialog = false;
process.StartInfo.RedirectStandardInput = true;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.EnableRaisingEvents = true;
process.Start();
但我认为您的路径无效。你能 Debug.Log 它并在评论中写下它是什么吗?它应该是绝对路径 btw
解决方案是像这样定义进程的目录:
Process p = new Process();
p.StartInfo.FileName = path + "app.exe";
p.StartInfo.WorkingDirectory = path;
p.Start();
其中 path
是 app.exe 所在文件夹的路径。