您可以使用
subprocess.Popen和
subprocess.communicate将输入发送到另一个程序。
例如,将“ enter”键发送到以下程序
test_enter.py:
print "press enter..."raw_input()print "yay!"
您可以执行以下操作:
from subprocess import Popen, PIPEp = Popen(['python test_enter.py'], stdin=PIPE, shell=True)p.communicate(input='n')
您可能还会发现“如何编写python子进程的stdin”的答案也很有帮助。



