简体   繁体   中英

Run a command line process from unity

I am trying to run an external .exe file with argument from unity, this what I have been doing:

ProcessStartInfo startInfo = new ProcessStartInfo("AAA.exe");
startInfo.WindowStyle = ProcessWindowStyle.Normal;      
startInfo.Arguments = "MyArgument";         
Process.Start(startInfo);

But an error keeps telling me that unity couldn't find the executable file. How can I add a path or make unity find the executable file? Advance Thanks.

It appears you may be giving an incorrect Path to your .exe

Try something like this:

string fullPath = Path.Combine(Environment.CurrentDirectory, "/YourSubDirectory/yourprogram.exe");

ProcessStartInfo startInfo = new ProcessStartInfo(fullPath);
startInfo.WindowStyle = ProcessWindowStyle.Normal;
startInfo.Arguments = "MyArgument";

Process.Start(startInfo);

Application Paths in Unity - Dependent on where your .exe is based, this may be of use.

好了,您可能需要使用相对于您的统一build.exe文件夹的路径才能使其正常工作

You should either specify the full path or a relative path of the executable. Check this post for some examples.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM