Search code examples
pythonpython-2.7subprocessmplayer

Run mplayer using subprocess in Python erro


I want to run mplayer using python and here is my code

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

but it is not working I got this error

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

What I am doing wrong ?


Solution

  • You need to pass a list of args with shell=False(which is the default):

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

    Or with a single string you would need shell=True:

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

    But there is no need for the latter, the first will work fine.