我需要做这样的事情,但我需要创build一个可以给予input和输出多次的subprocess。 该post的接受答案有很好的代码… from subprocess import Popen, PIPE, STDOUT p = Popen(['grep', 'f'], stdout=PIPE, stdin=PIPE, stderr=STDOUT) grep_stdout = p.communicate(input=b'one\ntwo\nthree\nfour\nfive\nsix\n')[0] print(grep_stdout.decode()) # four # five …我想继续像这样: grep_stdout2 = p.communicate(input=b'spam\neggs\nfrench fries\nbacon\nspam\nspam\n')[0] print(grep_stdout2.decode()) # french fries 但是,唉,我得到以下错误: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/opt/local/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/subprocess.py", line 928, in communicate raise ValueError("Cannot send input after […]