objective c - Trying to run cli with NSTask is failing -
i trying run next in cocoa app:
cat pathtofile | python -mjson.tool > outputfile
nstask *task = [[nstask alloc] init]; [task setlaunchpath: @"/bin/cat"]; nsarray *arguments = [nsarray arraywithobject: path]; [task setarguments: arguments]; nspipe *pipe = [nspipe pipe]; [task setstandardoutput:pipe]; [task launch]; nstask *task2 = [[nstask alloc] init]; [task2 setlaunchpath:@"/usr/bin/python"]; nsarray *arguments2 = [nsarray arraywithobject:[nsstring stringwithformat:@"-mjson.tool > %@.beautify", path]]; [task2 setarguments:arguments2]; [task2 setstandardinput:pipe]; nspipe *pipe2 = [nspipe pipe]; [task2 setstandardoutput:pipe2]; [task2 launch];
however getting next error: /usr/bin/python: import filename not supported.
any ideas?
seems more python error.
/usr/bin/python -mjson.tool
calls next file : (when used terminal)
/system/library/frameworks/python.framework/versions/2.7/lib/python2.7/json/tool.py
whose content is
""" headers...""" import sys import json def main(): if len(sys.argv) == 1: infile = sys.stdin outfile = sys.stdout elif len(sys.argv) == 2: infile = open(sys.argv[1], 'rb') outfile = sys.stdout elif len(sys.argv) == 3: infile = open(sys.argv[1], 'rb') outfile = open(sys.argv[2], 'wb') else: raise systemexit(sys.argv[0] + " [infile [outfile]]") try: obj = json.load(infile) except valueerror, e: raise systemexit(e) json.dump(obj, outfile, sort_keys=true, indent=4) outfile.write('\n') if __name__ == '__main__': main()
you task can't resolve these import statements. certainly because doesn't know much terminal does, , can't find this... see nstask not launching python right path
objective-c cocoa nstask
No comments:
Post a Comment