Home  >  Q&A  >  body text

python 利用subprocess库调用mplayer时发生错误

脚本在读取stdout时卡住,不再继续执行,也不发生终止

import subprocess
 
p = subprocess.Popen(["mplayer", "-slave", "-quiet", "/home/pi/Music/爱的翅膀.mp3"], stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = False)
 
p.stdin.write('\n') 
print p.stdout.read() //此处
p.stdin.write('get_time_pos\n')
print p.stdout.read()
伊谢尔伦伊谢尔伦2740 days ago562

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:23:43

    When mplayer plays, a large number of characters will be input to stout. If the number exceeds 4096, it will cause a deadlock. The output information is not what I want, so I decided to modify it stdout=open("/dev/null","w") to solve the problem. Reference blog http://blog.csdn.net/imzoer/a...

    reply
    0
  • Cancelreply