I want to call a python
script from Java. My python version is 2.5 and Java is 6.
My current code:
try{
Process p= Runtime.getRuntime().exec("path/dirs/file.py");
p.waitFor();
} catch (InterruptedException ex){
System.out.println(ex.getMessage());}
}
The error I receive is:
Java.IO.IOException: Cannot run program filename: CreateProcess error = 193, %1 is not a valid Win32 application
You can run only a windows executable like a EXE or BAT file using the Runtime.exec function. You need to find a way to instantiate the Python interpreter and then give the file name using a .BAT File.
The easiest way to integrate a Java application with Python is to use Jython.
I have used this successfully in the past to build scriptable java applications before we had access to Nashorn and it's ilk.
try this, This works for me
test_python.py
interpreterPython.java
Try to use
PrecessBuilder
-See here from more detail.