如何在java中使用ProcessBuilder调用Python文件中的方法?我的Python文件有一个类和三个方法。另外,如何从ProcessBuilder设置python方法参数?在
以下是我的Java代码:public void con3(){
try {
ProcessBuilder pb = new ProcessBuilder("C:\\Python34\\python.exe", "D:\\New folder\\test\\src\\NewCodes\\pickel4output.py","may","vay");
Process p = pb.start();
System.out.println(p);
BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
System.out.println("Running Python starts: " + line);
int exitCode = p.waitFor();
System.out.println("Exit Code : "+exitCode);
line = in.readLine();
System.out.println("First Line: " + line);
while ((line = in.readLine()) != null){
System.out.println("Python Output: " + line);
}
}
}
这是我的Python代码的一部分:
^{pr2}$