aspose file tools*
The moose likes Jython/Python and the fly likes Calling python function from java . NEED HELP URGENT Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Languages » Jython/Python
Reply locked New topic
Author

Calling python function from java . NEED HELP URGENT

Geetu Kumari
Greenhorn

Joined: Mar 10, 2008
Posts: 5
Hi

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,
Geeta

I tried for this ... but it not giving any error and not executing also .....

public class MyJavaClass
{
public static void main(String[] args)
{
try
{
System.out.println("start");
String file = "/home/geeta/Install/newEclipse/NoCrashPlease/testWebProject/src/pythonPrograms/test.py" ;
Process p =Runtime.getRuntime().exec("chmod -R 777 " + file);
p.waitFor();
p = Runtime.getRuntime().exec("python " +file);
p.waitFor();
System.out.println("end........................");
}
catch (Exception e)
{
e.printStackTrace();
}
}
}

/* test.py contain */
print 'SUCCESS'
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41853
    
  63
Please do not post the same question to multiple forums: CarefullyChooseOneForum

Let's continue the discussion in this duplicate thread.


Ping & DNS - my free Android networking tools app
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Calling python function from java . NEED HELP URGENT