0

The title may not be the best description of what I'm trying to do. I made a few simple lines of code to run a .exe, in this case the adobe reader installer.

import os os.system('"D:/Python Project/Work Project/Installers/readerdc_en_xa_crd_install.exe"') 

currently the code and .exe are in the same folder but if I were to move the entire folder to another machine obviously the file path for the .exe would no longer be the same. How do I go about running a .exe that is in the same folder as the code without relying on the entire file path of the machine?

Thanks

0

1 Answer 1

0
import os mypath = os.path.abspath(os.path.dirname(__file__)) os.system( f'"{mypath}/readerdc_en_xa_cer_install.exe"' ) 
Sign up to request clarification or add additional context in comments.

6 Comments

ok im being dumb what should be in the parenthesis after dirname? should it be the name of the .exe or?
that returns an error Traceback (most recent call last): File "D:/Python Project/Work Project/GUITest/InstallTest.py", line 2, in <module> mypath = os.path.abspath(os.path.dirname(FILE)) NameError: name 'FILE' is not defined
Try __file__ rather than __FILE__.
that worked but now i get an error "'D:\Python' is not recognized as an internal or external command, operable program or batch file."
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.