运行 mplayer 在 Python 错误中使用子进程

Run mplayer using subprocess in Python erro

我想 运行 mplayer 使用 python 这是我的代码

from subprocess import call 
call (mplayer /root/Desktop/file.mp4)

但它不工作我收到了这个错误

File "two.py", line 8, in <module>
    call ("mplayer /root/Desktop/file.mp4")
  File "/usr/lib/python2.7/subprocess.py", line 493, in call
    return Popen(*popenargs, **kwargs).wait()
  File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
    errread, errwrite)
  File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
    raise child_exception

我做错了什么?

您需要使用 shell=False(默认设置)传递一个参数列表:

call(["mplayer", "/root/Desktop/file.mp4"])

或者对于单个字符串,您需要 shell=True:

call("mplayer /root/Desktop/file.mp4", shell=True)

但是后者没有必要,第一个就可以了。