I have a shell script in my JSON document jsonStr
.. I am trying to execute that shell script using Python subprocess module after deserializing the jsonStr -
#!/usr/bin/python
import subprocess
import json
jsonStr = '{"script":"#!/bin/bash \\n STRING="Hello World" \\n echo $STRING \\n"}'
j = json.loads(jsonStr)
print "start"
subprocess.call(j['script'], shell=True)
print "end"
But somehow whenever I run my above python script, I always get an error like this -
Traceback (most recent call last):
File "shellscript", line 27, in <module>
j = json.loads(jsonStr)
File "/usr/lib/python2.7/json/__init__.py", line 326, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 366, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting , delimiter: line 1 column 34 (char 34)
Any thoughts what wrong I am doing here?