【发布时间】:2012-06-15 20:26:08
【问题描述】:
main.py
import subprocess,sys
process = subprocess.Popen([sys.executable]+['example.py'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
while True:
out = process.stdout.read(1)
if not out:
out=process.stderr.read(1)
if out == '' and process.poll() != None:
break
if out != '':
print out
example.py
f=raw_input('WHats your favorite animal')
好的,我想知道如何检查主循环中的输入并为其提供一些数据。现在,当我使用 raw_input 时,我的程序会冻结。
这就是我想要的
while True:
out = process.stdout.read(1)
if not out:
out=process.stderr.read(1)
if out == '' and process.poll() != None:
break
#showing what i want
if request_input==True:
give_input('cat') #Give input to the raw_input
#
if out != '':
print out
不知道有没有这样的功能。如果您需要更多解释,请发表评论。
【问题讨论】:
-
我什至愿意使用 C++ 的东西来让它工作。 IDLE.py 是怎么做到的?
标签: python multiprocessing subprocess