Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 Launching other programs from Python
import subprocess
gives an error
C:\Python36\kodovi> File "C:\Python36\kodovi\", 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.
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.
Truman likes this post
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Thank you, now I got this one
C:\Python36\kodovi> Traceback (most recent call last): File "C:\Python36\kodovi\", line 88, in <module> subprocess.Popen(r'C:\Users\user\Desktop\notepad.lnk') File "C:\Python36\lib\", line 709, in __init__ restore_signals, start_new_session) File "C:\Python36\lib\", 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.
That one I don't know, I am not familiar with the subprocess module.
Craig "Ichabod" O'Brien -
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

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.

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Launching executable over rest server api InsatiableBuns 0 326 Oct-25-2018, 12:22 PM
Last Post: InsatiableBuns
  Different runtime programs mhvozdesky 1 293 Oct-24-2018, 02:50 PM
Last Post: ichabod801
  pipeline between 2 programs Skaperen 11 1,265 Jul-02-2018, 10:48 PM
Last Post: Skaperen
  How to Load Idle/Cmd Programs to Server? georgejr6 6 1,159 Jun-24-2018, 07:33 PM
Last Post: snippsat
  Executing DOS programs within Python mdsi2000 4 835 Mar-01-2018, 03:49 PM
Last Post: mdsi2000
  String Programs PythonLearner 1 921 Feb-15-2018, 03:00 PM
Last Post: sparkz_alot
  Issue with Python 3.X Add/Remove programs entry. WilliamM 1 827 Feb-08-2018, 01:54 PM
Last Post: sparkz_alot
  SOLVED: best way to block (wait on) shell calls to multiple windows programs at once? ezdev 0 680 Dec-10-2017, 06:42 AM
Last Post: ezdev
  Program-launching script will not close until the program it launches is closed mmwatson 1 1,301 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 4,982 Jun-02-2017, 10:44 PM
Last Post: python300

Forum Jump:

Users browsing this thread: 1 Guest(s)