如何在java里面调用python,并且与python程序进行交互

huhuint huhuint 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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信息输出到哪里了?
...全文

相关推荐

评论 1
收藏 已收藏
分享
返回顶部
huhuint
Java 51,407 成员 86,131 内容