0

I'm trying to launch an executable from python subprocess and I have a problem with the path. I'm trying to run newman.cmd which is located in

C:\Users\<myself>\AppData\Roaming\npm

I try

subprocess.run("C:\Users\<myself>AppData\Roaming\npm\newman.cmd run","shell=True")

which fails, indicating:

Syntax Error: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape: C:\knxnet\test_differentiel.py, line 71, pos 23
subprocess.run("C:\Users\<myself>\AppData\Roaming\npm\newman.cmd run","shell=True")

If I copy newman.cmd and the appropriate folders in my local path, I end up launching the command as expected, ie. this works:

subprocess.run("newman.cmd -h")

I checked the path and it gives me the following:

ENV =  <irrelevant info> ;C:\Users\<myself>\AppData\Roaming\npm

so I though it would find it ? how can I do to avoid copying executables in my current directory ?

thanks for any help ...

A.Joly
  • 2,317
  • 2
  • 20
  • 25

1 Answers1

0

Well, I found out the answer thanks to SO ... "Unicode Error "unicodeescape" codec can't decode bytes... Cannot open text files in Python 3

It is interpreted as unicode followed by an unwanted character ... the position indicated in the error was the quote's position, so I didn't catch the hint. so I tried with r:

subprocess.run(r"C:\Users\a.joly\AppData\Roaming\npm\newman.cmd -h")

and it works. It also works if I double the "\".

thanks for your time ...

A.Joly
  • 2,317
  • 2
  • 20
  • 25