Python Forum
Launching other programs from Python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/Forum-Python-Coding)
+--- Forum: General Coding Help (https://python-forum.io/Forum-General-Coding-Help)
+--- Thread: Launching other programs from Python (/Thread-Launching-other-programs-from-Python)



Launching other programs from Python - Truman - Feb-12-2019

import subprocess
subprocess.Popen('C:\Users\user\Desktop\notepad.lnk')
gives an error
Error:
C:\Python36\kodovi>times.py File "C:\Python36\kodovi\times.py", line 88 subprocess.Popen('C:\Users\user\Desktop\notepad.lnk') ^ SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in positio n 2-3: truncated \UXXXXXXXX escape
I'm trying to open a notepad but it gives error that I don't understand.


RE: Launching other programs from Python - ichabod801 - Feb-12-2019

Backslashes indicate special characters. \U indicates a unicode character. That's causing your error. Either double the backslashes ('C:\\Users...') or make it a raw string (r'C:\Users...') which will ignore backslash encodings.


RE: Launching other programs from Python - Truman - Feb-13-2019

Thank you, now I got this one
Error:
C:\Python36\kodovi>times.py Traceback (most recent call last): File "C:\Python36\kodovi\times.py", line 88, in <module> subprocess.Popen(r'C:\Users\user\Desktop\notepad.lnk') File "C:\Python36\lib\subprocess.py", line 709, in __init__ restore_signals, start_new_session) File "C:\Python36\lib\subprocess.py", line 997, in _execute_child startupinfo) OSError: [WinError 193] %1 is not a valid Win32 application
how everything looks simple in the book but complicated when you have to make it work.


RE: Launching other programs from Python - ichabod801 - Feb-13-2019

That one I don't know, I am not familiar with the subprocess module.


RE: Launching other programs from Python - Truman - Feb-14-2019

For those who are interested in this topic the correct code should be:
subprocess.Popen(r'C:\Users\user\Desktop\notepad.lnk', shell=True)
Shortcuts are not recognized by subprocess as an application.