I am trying to execute a windows executable which could be located in "c:\program files\folder"
using python. The get_me_the_path()
routine returns the exe path located in "c:\program files\folder"
.
I tried various things like replacing "\"
with "\\"
and " "
with "\ "
OR even changing "\
" to "/"
BUT everytime I get the same error
Issue is that i want to convert output_path
variable to some form which subprocess.check_output
can execute without issues. Few people suggested normpath
but that too doesn't help and I get the same error.
try:
output_path= os.path.join(get_me_the_path()) ;
exepath = output_path.replace("\\", "/").replace(" ", "\\ ")
subprocess.check_output(exepath,shell=True,stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
raise RuntimeError("command '{}' return with error (code {}): {}".format(e.cmd, e.returncode, e.output))
This is the error I am getting every time
RuntimeError: command 'C:/Program\ Files/folder/mytool.exe' return with error (code 1):
b"'C:/Program\\' is not recognized as an internal or external command, operable program
or batch file.