1

Python スクリプトを使用して、rpi3 のコマンド ラインで omxplayer を制御しようとしています。subprocess.Popen を呼び出して制御します (再生/一時停止、音量の増減など)。標準入力 (例: p、+/- など)、文字は send_signal で変数テキストとして渡され、通信を使用して制御できません。より良い方法はありますか?

編集: また、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()

omxplayer の代わりに cat -e を試してみると、出力は次のようになります。

why_dont_you work
test_input
test_input$
test_input2
test_input2$
a
a$

どういうわけか最初の行が再び表示されないことに注意してください

4

1 に答える 1

0

渡すものが入力変数であることを指定する必要があります

def send_signal(player, text):
    player.communicate(input=text.encode('utf-8'))
    player.stdin.close()
于 2016-12-06T18:27:38.393 に答える