2

I am trying to run a python script from another as follows, some of the arguments take quotes ("),how do I run this command with quotes?

cmd =  r"python ./clone.py -u username -rl %s -ra adar.py -d 13346612 -at "Cloning for automation" -m "Pace" -r "Cloning for automation" "%radar
proc = Popen(cmd.split(' '), stdout=PIPE, stderr=PIPE)

UPDATE#1:I tried the following suggestions but none of them worked

  (i)escape the quotes
  (ii)Use multi line quotes
  (iii)Use single quotes as delimiter

UPDATE#2:

I tried to run with shell=TRUE but the python script hungs

wisecrack
  • 315
  • 2
  • 12
  • change `"C....` to `\"C....` – eyllanesc Feb 02 '18 at 22:03
  • Possible duplicate of [How to include a quote in a raw Python string?](https://stackoverflow.com/questions/4630465/how-to-include-a-quote-in-a-raw-python-string) – eyllanesc Feb 02 '18 at 22:03
  • one possible way could be to run command as shell script from python, Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True ). if you can use this, then it might solve your problem. – SHAHS Feb 02 '18 at 23:03
  • @SHAHS - if I run as shell, its just hung, any other pointers? – wisecrack Feb 02 '18 at 23:09

2 Answers2

0

You can use single quotes ' to delimit your string and double quotes " inside the string to delimit your arguments.

Alvaro Bataller
  • 487
  • 8
  • 29
0

Use a multi-line string

Wrap the cmd in 3 single quotes on each side:

i.e.:

cmd =  ''' 
python ./clone.py -u username -rl {} -radar.py -d
13346612 -at "Cloning for automation" -m "Pace" -r "Cloning for
automation"  
'''.format(radar)
adivis12
  • 471
  • 6
  • 12
  • this didn't work either, the `Popen` fails to run a multi line string – wisecrack Feb 02 '18 at 22:46
  • ` proc = Popen(cmd.split(' '), stdout=PIPE, stderr=PIPE) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 710, in __init__ errread, errwrite) File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1335, in _execute_child raise child_exception OSError: [Errno 13] Permission denied` is the exact error – wisecrack Feb 02 '18 at 22:51