I am trying to open a shortcut for Notepad called Notepad.lnk
.
Because I want to learn how to open applications so I can use the pygui library to manipulate them.
Got FileNotFoundError
I got this error:
Traceback (most recent call last):
File "C:\Users\{my_name}\PycharmProjects\texture-gen\main.py", line 185, in <module>
subprocess.run(['start', shortcut_path], check=True)
File "C:\Users\{my_name}\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 505, in run
with Popen(*popenargs, **kwargs) as process:
File "C:\Users\{my_name}\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 951, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\{my_name}\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 1420, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] The system cannot find the file specified
Code
This is my python code:
if __name__ == '__main__':
import os
import subprocess
cwd = os.getcwd()
shortcut_path = os.path.join(cwd, 'Notepad.lnk')
if not os.path.exists(shortcut_path):
print('Error: "Notepad.lnk" shortcut not found')
subprocess.run(['start', shortcut_path], check=True)
Debugging
I have checked the name of the shortcut is Notepad.lnk
and is in the current working directory.
Why is this not working?