'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 1:[1]
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")])
Solution 2:[2]
Verify that the path exists:
import os
print os.path.exists("C:\Users\Kamilos\Desktop\TBT\Tbt_S01E17.avi")
Solution 3:[3]
It worked this way for me:
os.system(''start vlc C:\\local\\file\\name.mp4")
or:
subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe","C:\\Users\\USERNAME\\Desktop\\videos\\example.mp4"])
-the difference is in the way to put the: ' \ ' , ' // '
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | Onlyjus |
Solution 3 | Eric Aya |