Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch VLC through Python

Tags:

python

vlc

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"])‌​
like image 482
Lol Pallau Avatar asked Oct 07 '22 15:10

Lol Pallau


1 Answers

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")])
like image 67
pR0Ps Avatar answered Oct 19 '22 12:10

pR0Ps