Passing java jar output to python in an efficient way -


i trying speed way call java jar python saving resulting string (java system.out.println) in python list. used write directl file java, found slow, opening , closing file each time, trying speed up.

i have:

subprocess.call(             ['java', '-jar', 'tensiontwoslices.jar', '-runtype', '"groundtruth"', '-inputwindow', inputwindow, '-outputwindow', groundtruth,              '-inputfile', '"not.txt"', '-key', '"c"'],stdout=subprocess.pipe, stderr=subprocess.pipe); 

i read here can use stdout, tried:

 p = subprocess.popen(                 ['java', '-jar', 'tensiontwoslices.jar', '-runtype', '"groundtruth"', '-inputwindow', inputwindow, '-outputwindow', groundtruth,                  '-inputfile', '"not.txt"', '-key', '"c"'],stdout=subprocess.stdout, stderr=subprocess.pipe);           print p.stdout; 

but getting:

traceback (most recent call last):   file "extract_tension.py", line 65, in <module>     '-inputfile', '"not.txt"', '-key', '"c"'],stdout=subprocess.stdout, stderr=subprocess.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 9] bad file descriptor 

as not longer writing file believe can switch call popen.

but it's essential nothing written terminal speed extremely important (running millions of times).

what fastest way of passing system.out.println java python list?

try -

output = subprocess.check_output(     ['java', '-jar', 'tensiontwoslices.jar', '-runtype',       '"groundtruth"', '-inputwindow', inputwindow, '-outputwindow',       groundtruth, '-inputfile', '"not.txt"', '-key', '"c"'])  print output 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -