0
我有一个从python到stdin的stdout在java中。stdout从python到stdin java
我使用
Python代码
p = subprocess.Popen(command, stdout = subprocess.PIPE, stdin = subprocess.PIPE)
p.stdin.write("haha")
print "i am done" #it will never hit here
Java代码
Scanner in = new Scanner(System.in)
data = in.next()// the code blocks here
基本上会发生什么是 子进程运行jar文件--->它块作为标准输入是仍然阻塞,因为它显示没有内容
你有什么问题? – 2015-03-03 02:27:38
@MalikBrahimi代码不会打印p.stdout.read()也许我应该修改以更好地展示它 – aceminer 2015-03-03 02:29:36
这可能有所帮助:http://stackoverflow.com/questions/163542/python-how-do-i- pass-a-string-into-subprocess-popen-using-stdin-argument基本上,使用p.communicate()而不是p.stdin.write。 – matiasg 2015-03-03 02:55:43