0

Hello! I am having trouble getting the abspath when entering only an executable file. How can I fix this to return the full abspath? I am taking user input and opening a process (application). 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")

When args[2] = 'firefox', this 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

Any suggestions? Thanks!

Edited by PhilEaton

2
Contributors
2
Replies
3
Views
4 Years
Discussion Span
Last Post by PhilEaton
-1

Apparently the only way to do this is by searching through windows folders to find the folder that actually contains the executable file. I did this by looping through Windows' Program Files folder to find a folder that contained the same name that the executable had. Actually worked quite nicely.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.