上一篇博客讲了不需要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();
}
}
}