I am trying to write a Java application that executes a python script in order to return a value to the original program. However, the script is written in Python3 so I can't use Jython.
My current program works fine in Intellij but when I export to a JAR file it no longer works (I'm assuming because the filepath is different). I know questions similar to this have been asked in the past but none of the solutions seem to be working.
String currentPath = new File("").getAbsolutePath();
String path = Paths.get(currentPath, "src", "com", "engine", "pythonScript.py").toUri().toString();
String[] cmd = new String[]{"python", path, data};
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
String output;
while ((output = stdInput.readLine()) != null) {
System.out.println(output);
if (checkOutput(output)) {
return output;
}
}
BufferedReader error = new BufferedReader(new InputStreamReader(p.getErrorStream()));
String s;
while ((s=error.readLine()) != null) {
System.out.println(s);
}
} catch (IOException e) {
e.printStackTrace();
}