Calling python function from java . NEED HELP URGENT
Joined: Mar 10, 2008
I want to call python function from java Class OR execute python file from java Class
if possible Please explain me with piece of code urgently .......
Thanks in advance,
I tried for this ... but it not giving any error and not executing also .....
public class MyJavaClass
public static void main(String args)
String file = "/home/geeta/Install/newEclipse/NoCrashPlease/testWebProject/src/pythonPrograms/test.py" ;
Process p =Runtime.getRuntime().exec("chmod -R 777 " + file);
p = Runtime.getRuntime().exec("python " +file);
catch (Exception e)
/* test.py contain */
Joined: Mar 22, 2005
Instead of Runtime.exec(String) I'd recommend to use Runtime.exec(String). This and other tips on using Runtime.exec -like dealing with the process's streams- are explained in detail in the article "When Runtime.exec() doesn't" by Daconta (which is really required reading when using it).
I think it's spelt "When Runtime.exec() won't", but as Ulf has said, you need to find it with Google and read it. It is a little easier now the ProcessBuilder class has been introduced, but only slightly easier. And don't go saying your request is urgent.
This question is too difficult for the beginners' forum. Moving.
author and iconoclast