我有一个名为 1st.py
的脚本,它创建了一个 REPL (read-eval-print-loop) :
print "Something to print"
while True:
r = raw_input()
if r == 'n':
print "exiting"
break
else:
print "continuing"
然后,我用以下代码启动了 1st.py
:
p = subprocess.Popen(["python","1st.py"], stdin=PIPE, stdout=PIPE)
然后试了这个:
print p.communicate()[0]
它失败了,提供了这个回溯:
Traceback (most recent call last):
File "1st.py", line 3, in <module>
r = raw_input()
EOFError: EOF when reading a line
你能解释一下这里发生了什么吗? 当我使用 p.stdout.read()
时,它会永远挂起。