Reputation: 11
def run():
subprocess.call("C://Users//FIN//Documents//python//react_bot//discord bot//dist//app.exe",shell=True)
print("app loaded")
run()
I have this code which will call and open the application which is in C://Users//FIN//Documents//python//react_bot//discord bot//dist directory because i have my stuff there. What if i want to call for an application which is in the same directory as the python script. How do i do that ?
Upvotes: 0
Views: 363
Reputation: 15470
You can first get the parent directory of current script and join it with the application name and run it:
import os
import subprocess
mydir = os.path.dirname(os.path.abspath(__file__))
theapp = os.path.join(mydir, 'YOUR APPLICATION NAME.EXTENSION')
subprocess.call(theapp)
Upvotes: 0
Reputation: 1440
You should be able to solve your problem with the following:
import os
import subprocess
dirname = os.path.dirname(os.path.abspath(__file__))
cmd = os.path.join(dirname, 'app.exe')
subprocess.call(cmd)
Upvotes: 1