Python Forum

Full Version: Windows paths issue
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Using Python 3.7 on Windows 10 pro, I ran to the strange thing:
Path to vlc.exe on my PC is: C:\Program Files\VideoLAN\VLC\vlc.exe. In my script, I've defined it as: fullpath = "\"C:\\Program Files\\VideoLAN\\VLC\\vlc.exe\""
The strange thing is that when I run: subprocess.Popen(fullpath, stdout=None, stderr=None, stdin=None, close_fds=True), that works correctly, but when I run the:
os.system("taskkill /f /im " + fullpath) it fails with: ERROR: Invalid query. When I tested if the file exist with os.path.exists(fullpath) it returned False

I googled around and according to what I found, I think I defined path correctly, so I don't understand why it works with the subprocces.popen and not in other cases? BTW: I also replaced the double backslashes with single forward slashes but the issue remained the same
Can you print(repr(fullpath)) to see what it contains?
When vlc.exe runs, open a cmd.exe and execute "tasklist /v /fo csv". Can you find vlc.exe? What does it show exactly?
What happens when you define "fullpath = r"C:\Program Files\VideoLAN\VLC\vlc.exe"?
What happens when you do "taskkill /f /im vlc.exe"?
You don't give full path when shall close the process.
It's only name vlc.exe or PID.
Don't need "\" before the path.

import subprocess

subprocess.Popen([r"C:\Program Files\VideoLAN\VLC\vlc.exe"])
Kill💀
import subprocess

process = subprocess.run("taskkill /im vlc.exe", capture_output=True, encoding='utf-8')
print(process.stdout)
Output:
SUCCESS: Sent termination signal to the process "vlc.exe" with PID 21356.