1

I have a web application script written in Python that I store in my resources folder. I can access the file without a problem, but I am having trouble executing the script after deploying my Java application. To launch the script I have:

File f = new File(this.getClass.getClassLoader.getResource("/InterWebApp.py").getFile());
Process process = Runtime.getRuntime().exec("python " + f.getPath());
process.waitFor();

This does not launch the script, or if it does the process is dying immediately. When a monitoring class looks at process every 120 seconds, the process is not alive. I am deploying my application on a company platform and simpler processes like gedit newFile do work and launch the window, but I cannot get my Python script to launch, which I am assuming is because when the process is launching it might not have direct access to the resource files. Any ideas?

EDIT: I have also tried:

String scriptFilePath = System.getProperty("user.dir") + "/src/main/java/com/pkg/resources/InterWebApp.py";
Process process = Runtime.getRuntime.exec("python " + scriptFilePath);

I've tried an absolute path before, but the issue I have is the working directory when I deploy my application contains a JAR containing the resources and not the directory structure specified in the absolute path.

SVN600
  • 325
  • 1
  • 4
  • 17
  • Have you tried to use an absolute path for the python executable? – Sebastian Jul 28 '16 at 20:12
  • Yes, the problem with that is it can't access the resources file in the JAR – SVN600 Jul 28 '16 at 20:25
  • 1
    Copy the file to the filesystem first. The code in this answer isn't perfect, but it's a starting point: http://stackoverflow.com/a/35465681/611819 – dnault Jul 28 '16 at 21:48

0 Answers0