On Feb 15, 2017, at 2:57 PM, Cannon Smith via 4D_Tech <[email protected]> wrote: > > I’ve been given a python script which takes JSON and returns JSON with all > the keys alphabetized which is helpful for comparing revisions in version > control. However, I can’t figure out how to use LAUNCH EXTERNAL PROCESS and > pass some JSON to it and get the result back. If anyone here knows how it can > be done, I’d appreciate the help (I know nothing about python). MacOS if it > matters. > > Here is the script: > > #!/usr/bin/python > import fileinput > import json > if __name__ == "__main__": > jsonStr = '' > for a_line in fileinput.input(): > jsonStr = jsonStr + ' ' + a_line.strip() > jsonObj = json.loads(jsonStr) > print json.dumps(jsonObj, sort_keys=True, indent=2)
I’m not familiar with python, but according to the docs, fileinput.input() will use stdin (standard input) if no file names are provided as arguments. LEP provides a parameter for stdin, so theoretically you should be able to pass the JSON to the script using LEP's inputStream parameter and get the result using LEP's outputStream variable. If this doesn’t work, a bug should be filed because there isn’t any other purpose for the inputStream parameter I can think of. The script should be executable like any other script, by setting it to executable (chmod +x script.py). https://docs.python.org/2/library/fileinput.html http://doc.4d.com/4Dv15/4D/15.4/LAUNCH-EXTERNAL-PROCESS.301-3274883.en.html Jim Crate ********************************************************************** 4D Internet Users Group (4D iNUG) FAQ: http://lists.4d.com/faqnug.html Archive: http://lists.4d.com/archives.html Options: http://lists.4d.com/mailman/options/4d_tech Unsub: mailto:[email protected] **********************************************************************

