Python Forum
Launching other programs from Python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Launching other programs from Python
#1
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.
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
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.
Reply
#4
That one I don't know, I am not familiar with the subprocess module.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#5
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  launching executables DPaul 6 1,339 Jan-15-2023, 02:45 PM
Last Post: DeaD_EyE
  python --version yields no output, not detected by other programs ten 3 3,365 Jun-25-2020, 04:48 AM
Last Post: perfringo
  Can Cmder be used to write Python programs? newbieAuggie2019 5 4,953 Sep-30-2019, 11:24 AM
Last Post: newbieAuggie2019
  Launching executable over rest server api InsatiableBuns 0 1,960 Oct-25-2018, 12:22 PM
Last Post: InsatiableBuns
  Executing DOS programs within Python mdsi2000 4 3,855 Mar-01-2018, 03:49 PM
Last Post: mdsi2000
  Issue with Python 3.X Add/Remove programs entry. WilliamM 1 3,124 Feb-08-2018, 01:54 PM
Last Post: sparkz_alot
  Program-launching script will not close until the program it launches is closed mmwatson 1 3,217 Jun-21-2017, 10:31 PM
Last Post: Ofnuts
  Issue in launching spyder that was installed using pip install on Python 3.6.1 python300 6 10,993 Jun-02-2017, 10:44 PM
Last Post: python300

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020