上一篇博客講了不需要Java調用Python腳本不需要傳參的解決辦法,這篇博客主要講一下需要傳參數時如何解決。
import java.io.BufferedReader;
import java.io.InputStreamReader;
public static void main(String[] args){
try{
System.out.println("open");
Process pr = Runtime.getRuntime().exec("python pythontest.py 參數1的值 參數2的值");
BufferedReader in = new BufferedReader(new
InputStreamReader(pr.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
pr.waitFor();
System.out.println(pr.exitValue());
} catch (Exception e){
e.printStackTrace();
}
}
}