0

I created a python file called leaderboard and made it into a .exe file using pyinstaller. This .exe file is in a folder called dist which is inside the data folder for my sketch. I first attempted to launch the file using the launch() function and while this gave me no errors it did not execute the file.

launch("data/dist/leaderboard.exe");

For my next attempt, I tried using the exec function instead.

exec("data/dist/leaderboard.exe");

This gave me the error code: Exception while attempting data/dist/leaderboard.exe

Next, I decided to use the full file path while using the launch function.

launch("C:/Users/Tahseen/Documents/cs corsework 2/Bloodlust/data/dist/leaderboard.exe");

This caused repeated popups with the title "fatal error detected" and the caption "unable to execute script leaderboard". Using exec() gave me this result too.

After researching I've found one solution that works for a few people is to use a double \ instead of a single / however this did nothing for me.

I confirmed that the file executes properly when opened manually from within the folder so I think the issue lies somewhere within my code.

UPDATE: I think that in the first two cases the file leaderboard.exe could not be located however I don't know why as when I put a random string inside the brackets the same thing happened. This lead me onto a second question: is there a way to execute a file from within the project folder i.e without the entire file path?

Tahseen
  • 13
  • 3
  • Maybe the exe needs access other sibling files ? You might need to to tell the `Process` (which `launch()` returns) which working directory to use. Try something like [this](https://stackoverflow.com/questions/8405723/how-to-set-working-directory-with-processbuilder) – George Profenza May 04 '20 at 22:28
  • you're right the exe file uses 2 text files in the same folder. How would I tell this to the Process in processing? – Tahseen May 05 '20 at 00:46
  • I can't test this now, but I'd try the snippet from the link above: ```Process p = null; ProcessBuilder pb = new ProcessBuilder("leaderboard.exe"); pb.directory(new File("C:/Users/Tahseen/Documents/cs\ corsework\ 2/Bloodlust/data/dist/"));p = pb.start();``` Alternatively you could try to use absolute paths in your python script too, through it's not a very flexible option. (Also pay attention to space and other special characters you may need to escape in Java, in general) . Unfortuantely I can't provide a detailed answer at the moment. Hopefully this makes sense / someone can answer. – George Profenza May 05 '20 at 00:56

1 Answers1

0

Thanks to @George Profenza I realised the issue was that the python file required external text files to run. While I couldn't figure out a way to reference which directory to use to the process, I figured out that instead of using text files to send data between processing and python I could use a client and server. I created a server on the processing project and a client on the python file by importing processing.net and socket. As for launching the exe file without manually entering the full file path I used dataPath("") to return the path of the data folder and then added "/dist/leaderboard.exe" to the resulting string. This way when exporting the application the program should still work.

String path = dataPath("");
launch(path+"/dist/leaderboard.exe");
Tahseen
  • 13
  • 3