I have a groovy code in which a python script is invoked. Is there a way to read the json serialized data printed/returned by the python script?
Groovy code to call python script:
def sout = new StringBuilder(), serr = new StringBuilder()
def cmd = ["python2.7","myscript.py"]
def proc = cmd.execute()
proc.consumeProcessOutput(sout, serr)
proc.waitFor()
def parser = new JsonSlurper()
def jsonResp = parser.parseText(sout[0])
log.debug(jsonResp)
Python script:
dd = {'key1': 'value1',
'key2':'value2',
'key3': {'key31':'value31'}
}
print json.dumps(dd)
Output:
jsonResp = {}
when the code is run.
jsonResp['key1']
also is empty implying that json is not read from process output.