My code is simply as follows:
file = 'C:\\Exe\\First Version\\filename.exe' os.system(file)
When I run this program, a Windows error is raised: can't find the file specified.
I found out the problem has to with the whitespace in the middle of "First Version". How could I find a way to circumvent the problem?
P.S.: what if the variable 'file' is being passed as an argument into another function?
Putting quotes around the path will work:
file = 'C:\\Exe\\First Version\\filename.exe' os.system('"' + file + '"')
but a better solution is to use the subprocess
module instead:
import subprocess file = 'C:\\Exe\\First Version\\filename.exe' subprocess.call([file])
I used this:
import subprocess, shlex mycmd='"C:\\Program Files\\7-Zip\\7z" x "D:\\my archive.7z" -o"D:\\extract folder" -aou' subprocess.run(shlex.split(mycmd))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With