I want to use Runtime.getRuntime().exec(String[] cmdarray, String[] envy, File dir)
,because I use relative direction in my python program. When I write this code; it doesn't work and no error report is shown.
Process proc1=Runtime.getRuntime().exec("python /Users/g/Documents/Project/fyp/Q/__init__.py 453454336",,/Users/g/Documents/Project/fyp/Q/)
proc1.waitFor();
I use java in my mac. python version is 2.7.
Actually what I want to do in Terminal is:
cd /Users/g/Documents/Project/fyp/Q/
python __init__.py
Seems as if you are passing some arguments to your .py file simply use
String command = "python /Users/g/Documents/Project/fyp/Q/__init__.py 453454336"
Runtime.getRuntime().exec(command)
Make sure you pass null
to the environment variables array and third parameter is actually a File object.
Use following code...!
File directory = new File("/Users/g/Documents/Project/fyp/Q/");
Process proc1=Runtime.getRuntime().exec("python /Users/g/Documents/Project/fyp/Q/__init__.py 453454336",null,directory)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.