Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Windows paths issue
#1
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
Reply
#2
Can you print(repr(fullpath)) to see what it contains?
Reply
#3
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"?
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  pdf2image, poppler and paths jehoshua 18 14,766 Jun-14-2022, 06:38 AM
Last Post: jehoshua
  automatically get absolute paths oclmedyb 1 2,127 Mar-11-2021, 04:31 PM
Last Post: deanhystad
  chkFile with absolute paths JarredAwesome 7 3,016 Sep-21-2020, 03:51 AM
Last Post: bowlofred
  Paths millpond 12 5,227 Jul-30-2020, 01:16 PM
Last Post: snippsat
  Problems with windows paths delphinis 6 5,205 Jul-21-2020, 06:11 PM
Last Post: Gribouillis
  Shortest paths to win snake and ladder sandaab 5 4,263 Jun-30-2019, 03:20 PM
Last Post: sandaab
  How to handle paths with spaces in the name? zBernie 1 6,745 Nov-22-2018, 04:04 AM
Last Post: ichabod801
  Question: Paths and writing to a file mwmaw 6 6,508 Dec-20-2016, 03:44 PM
Last Post: wavic

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020