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