如何在java里面调用python,并且与python程序进行交互
java代码
public static void main(String [] args){
try {
Process pr = Runtime.getRuntime().exec("python input.py");
BufferedReader in = new BufferedReader(new InputStreamReader(pr.getInputStream()));
String line;
while((line=in.readLine())!=null){
System.out.println(line);
}
in.close();
pr.waitFor();
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}
python代码
def input():
w=int(raw_input('input weight:'))
h=int(raw_input('input height:'))
s=w*h
print s
if __name__=='__main__':
input()
我想请教一下,单独执行input.py是可以的,但是在java里面调用就会卡住
请问input weight信息输出到哪里了?