5

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"])‌​ 
4
  • p = subprocess.Popen([r"C:\Program Files(x86)\VideoLAN\VLC\vlc.exe",r"C:\Users\Kamilos\Desktop\TBT\Tbt_S01E17.avi"]) Commented Sep 14, 2012 at 11:28
  • Thanks for help but it doesn't work neither, I've got always the same error Traceback (most recent call last): File "C:\Users\Kamilos\Desktop\site.py", line 2, in <module> Popen(["C:\Program Files (x86)\VideoLAN\VLC\vlc.exe"]) File "C:\Python32\lib\subprocess.py", line 736, in init restore_signals, start_new_session) File "C:\Python32\lib\subprocess.py", line 946, in _execute_child startupinfo) WindowsError: [Error 2] Le fichier spécifié est introuvable (The file cannot be found) Commented Sep 14, 2012 at 11:58
  • 3
    Try replace back-slash with blash. Ex, subprocess.Popen(["C:/Program Files(x86)/VideoLAN/VLC/vlc.exe","C:/Users/Kamilos/Desktop/TBT/Tbt_S01E17.avi"]) Commented Sep 14, 2012 at 14:07
  • @LolPallau: To mark a question as solved, click the check mark outline beside one of the answers. You'll have to get Drake to post his comment as an answer if you want to accept it. Commented Sep 14, 2012 at 16:57

3 Answers 3

6

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")]) 
Sign up to request clarification or add additional context in comments.

1 Comment

Better use 'C:\\' instead of 'C:/' as the result of 'C:\' will be 'C:/Program...)\...\...\vlc.exe' (note the wrong slash) while using '\\' will result correctly 'C:\Program Files(x86)\VideoLAN\VLC\vlc.exe'. both worked for me.
-1

Verify that the path exists:

import os print os.path.exists("C:\Users\Kamilos\Desktop\TBT\Tbt_S01E17.avi") 

Comments

-2

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: ' \ ' , ' // '

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.