- Home /
In build - Process cannot find file
Hello.
I'm making a game with Voice Recognition and I made it work alright in the editor. In one of the scripts in the Start function, I call a Process so it can start an external .exe. This .exe is needed in order for the speech recognition to work. I have this .exe in the Assets folder.
But when I make a build of the game I get this error in the output_log.txt file when I start the game.
Win32Exception: The system cannot find the file specified.
at System.Diagnostics.Process.Start_shell (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x00095] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/System/System.Diagnostics/Process.cs:969
at System.Diagnostics.Process.Start_common (System.Diagnostics.ProcessStartInfo startInfo, System.Diagnostics.Process process) [0x0008e] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/System/System.Diagnostics/Process.cs:1198
at System.Diagnostics.Process.Start () [0x0002c] in /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/System/System.Diagnostics/Process.cs:1210
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process:Start ()
at UDP_RecoServer.Start () [0x00030] in C:\Users\Valentina\VoiceTest\Assets\Scripts\UDP_RecoServer.cs:32 (Filename: /Users/builduser/buildslave/mono-runtime-and-classlibs/build/mcs/class/System/System.Diagnostics/Process.cs Line: 969)
Setting up 1 worker threads for Enlighten. Thread -> id: 14b8 -> priority: 1
So the question is how can I run that .exe in the build too? Is there another way I can reference to it?
Thank you.
Answer by hardcodednumber · Aug 10, 2015 at 04:04 PM
I think the best approach is to remove the EXE outside of your project. I would do a relative path from the Unity exe to the voice Recognition EXE.
For example,
(Path to the UnityGame.exe)//..bin//VoiceRecognition.Exe
I would also make sure this persist when you make an installer for your game!
Hmm, but the (Path to the UnityGame.exe) could be anything right? Let's say I set it to Desktop. If a user gets the game on their PC somewhere other than Desktop, how is my code going to know the path to my game? If I'm understanding correctly of course...could you give an example?
Ok I figured it out! You were right! I wrote this in my code:
myProcess.StartInfo.FileName = Application.dataPath + "/Server/RecoServeurX64.exe";
Application.dataPath stands for the game.exe folder that Unity builds, and the rest is the voice recognition folder which I just copied into the game.exe folder after I built it.
I have another problem though. This "RecoServeurX64.exe", once it starts it searches for a .txt file so it can read phrases and words for the voice recognition. This .txt is supposed to be in the same folder as the "RecoServeurX64.exe" for it to work. And it is. Although when I start the game.exe I can see the "RecoServeurX64.exe" opening fine in the task manager and then after a few seconds it closes which means it didn't find the .txt file. Any idea about that?
Does the path to the .txt file need to be absolute or relative. I would print the string arguments and see what the problem is.
On another note, since your game is depended on this process. I would use the Process class to make sure the process is at all running. For example, if the user closes RecoSereurX64.exe on accident. If they do, I'd fire off an event and stop your game or restart the exe.
I'm not sure if it has to be absolute, I think it might need to be. Here's what's going on in the pic:
I managed to print screen before it closed. The RecoSereurX64.exe, which is in the game executable folder, seems to be looking for the .txt file on the Desktop. Why is that? It should be looking into the same folder it is placed. When I place the .txt file on the Desktop the game seems to works well.
Yes that's a precaution I'll take too :)
EDIT: I got this written in my code so shouldn't it be looking in the correct folder rather than the Desktop?
myProcess.StartInfo.FileName = Application.dataPath + "/Server/RecoServeurX64.exe";
myProcess.StartInfo.Arguments = Application.dataPath + "/Server/grammar.txt";
//myProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
myProcess.Start();
Have you tried to make sure that the file path is valid? Open a explorer window and copy and past the path in there. It should open up to the file in notepad (or whatever your default program is). If it doesn't then the path isn't valid. Is their documentation on the program?
Your answer
Follow this Question
Related Questions
Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers
System.Diagnostics.Process.Kill() doesn't work 1 Answer
How can I stop the variable values reverting to its default values after being built? 1 Answer
Car Tutorial Raycast Issue since Upgrade Unity 4, Build fails editor works 1 Answer
How do I run an exe from unity without a window poping up. 1 Answer