Answer the question
In order to leave comments, you need to log in
Why is os.system not working?
I want to open a specific xls file using Microsoft Excel, command
"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE" "D:\Misha\Языки\Python\Excel\basics_0.xls"
in the console it does, but os.system returns an error when it is executed:>>> from os import system
>>> system (r'"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE" "D:\Misha\Языки\Python\Excel\basics_0.xls"')
1
Answer the question
In order to leave comments, you need to log in
It is necessary either to wrap each file name with a space in quotes, and escape the quotes, respectively, with a backslash, or try to use os.startfile
In general, it is recommended to run this business in a subprocess, something like this:
import subprocess
my_file = "c:/path/to/my_file.xls"
proc = subprocess.Popen(f"c:/program files/…/excel.exe {my_file}", shell=False)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question