我正在尝试使用 python 脚本在 rpi3 的命令行上控制 omxplayer,我调用 subprocess.Popen 并控制它(例如播放/暂停、增加/减少音量等..)我应该写一个字符到stdin(例如p,+/-等..),字符作为变量文本传入send_signal,使用communicate我无法控制它,有更好的方法吗?
编辑:还有player.stdin.write(text); player.stdin.flush() 不起作用。
def start_music():
player = subprocess.Popen(['omxplayer', songs[0]], stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.STDOUT)
return player
def send_signal(player, text):
player.communicate(text.encode('utf-8'))
player.stdin.close()
尝试使用 cat -e 而不是 omxplayer ,输出是:
why_dont_you work
test_input
test_input$
test_input2
test_input2$
a
a$
请注意,第一行不知何故不再显示
需要指定您传递的是输入变量,即
def send_signal(player, text):
player.communicate(input=text.encode('utf-8'))
player.stdin.close()