Search code examples
pythonvlc

Launch VLC through Python


To start vlc using python, I've done that :

import subprocess

p = subprocess.Popen(["C:\Program Files(x86)\VideoLAN\VLC\vlc.exe","C:\Users\Kamilos\Desktop\TBT\Tbt_S01E17.avi"])

But it doesn't work, why ? :p

(tested in python 2.7.3 and 3)

EDIT SOLVED : like Drake said, just replace back-slash with blash

subprocess.Popen(["C:/Program Files(x86)/VideoLAN/VLC/vlc.exe","C:/Users/Kamilos/Desktop/TBT/Tbt_S01E17.avi"])‌​

Solution

  • You are effectively escaping every character after the path separator. In the same way that "\n" means a new line, "\P", "\V" also mean something other than just a 2-character string.

    You could just use "\\" (or "/", can't remember which Windows uses) for the path separator, but the proper way is to get Python to join the path together for you using os.path.join.

    Try:

    import subprocess
    import os
    
    p = subprocess.Popen([os.path.join("C:/", "Program Files(x86)", "VideoLAN", "VLC", "vlc.exe"),os.path.join("C:/", "Users", "Kamilos", "Desktop", "TBT", "Tbt_S01E17.avi")])