子流程模块Python

子流程模块Python,python,multiprocessing,subprocess,Python,Multiprocessing,Subprocess,我们在使用Python中的子进程库时遇到了一个问题。我们试图通过函数communicate传递2条消息。第一个可以正常工作,但第二个会生成IOError 错误我认为我们可能错误地使用了子流程库的函数,但我们无法修复它。 有人能帮我们吗? 代码如下: from subprocess import * video=Popen("omxplayer myvideo.mp4",shell=True,stdout=PIPE,stdin=PIPE) video.stdin.write('+') vide

我们在使用Python中的子进程库时遇到了一个问题。我们试图通过函数communicate传递2条消息。第一个可以正常工作,但第二个会生成IOError 错误我认为我们可能错误地使用了子流程库的函数,但我们无法修复它。 有人能帮我们吗? 代码如下:

from subprocess import *

video=Popen("omxplayer myvideo.mp4",shell=True,stdout=PIPE,stdin=PIPE)

video.stdin.write('+')
video.stdin.flush()
result=video.stdout.read()
print "Vol +: "+result
video.communicate('p')
print "Pause"
错误是:

Traceback (most recent call last):
  File "youtube.py", line 55, in <module>
    proc.stdin.write('+')
IOError: [Errno 32] Broken pipe
回溯(最近一次呼叫最后一次):
文件“youtube.py”,第55行,在
进程stdin.write(“+”)
IOError:[Errno 32]管道破裂

谢谢

Popen.communicate会等待进程完成,因此当您尝试第二次调用时,进程已经停止。那么,使用函数write()、flush()和read()是否正确?是的。检查这个