I keep getting a 'cannot find file' error when trying to run this. Why is it not finding and assigning the absolute path? Here is my code:
file = "/" + arr[2] + ".exe"
print(file)
path = os.path.abspath(file)
print(path)
subprocess.Popen(path)
localtime = time.asctime(time.localtime(time.time()))
print(arr[2] + " opened at " + localtime + "\n")
Here is what is outputted:
/firefox.exe
C:\firefox.exe
Traceback (most recent call last):
File "C:\Python33\lib\subprocess.py", line 1090, in _execute_child
startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified
I am trying to programmatically find open a program based on user input... Maybe I am going about that the wrong way, but this is how somebody suggested doing it. Firefox.exe should be located at C:/Program Files/Firefox/firefox.exe
Any help would be great! Thanks!
file = r"C:/Program Files/Firefox/" + arr[2] + ".exe".exepath. Maybe you could try to make a dictionary likepaths = {'firefox': r'/path/to/firefox'}, then the path to user-selected app will bepaths[arr[2]].