Bottom Page

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.
Quote
#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.
Truman likes this post
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures

Quote
#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.
Quote
#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

Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Launching executable over rest server api InsatiableBuns 0 215 Oct-25-2018, 12:22 PM
Last Post: InsatiableBuns
  Different runtime programs mhvozdesky 1 208 Oct-24-2018, 02:50 PM
Last Post: ichabod801
  pipeline between 2 programs Skaperen 11 997 Jul-02-2018, 10:48 PM
Last Post: Skaperen
  How to Load Idle/Cmd Programs to Server? georgejr6 6 876 Jun-24-2018, 07:33 PM
Last Post: snippsat
  Executing DOS programs within Python mdsi2000 4 682 Mar-01-2018, 03:49 PM
Last Post: mdsi2000
  String Programs PythonLearner 1 718 Feb-15-2018, 03:00 PM
Last Post: sparkz_alot
  Issue with Python 3.X Add/Remove programs entry. WilliamM 1 681 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 565 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,178 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,195 Jun-02-2017, 10:44 PM
Last Post: python300

Forum Jump:


Users browsing this thread: 1 Guest(s)