Issues in getting the output when calling a python script from Java -
i've java program call python script. i've used exec method. please find code snippet below:
python program (which gather portion of text wikipedia), when run separately, gives me proper output. when called java, i'm not getting complete output python program.
i checked status of bufferedreader object using ready() method ( explained here, , code entered infinite loop.
i think others have faced similar problems-https://stackoverflow.com/a/20661352/3409074
can me?
public string enhancedata(string name,string entity) { string s = null; stringbuffer output = new stringbuffer(); try{ string command="python c://enhancer.py "+name+" "+entity; process p = runtime.getruntime().exec(command); bufferedreader stderror=new bufferedreader(new inputstreamreader(p.geterrorstream())); bufferedreader stdinput = new bufferedreader(new inputstreamreader(p.getinputstream())); while ((s = stdinput.readline()) != null) { system.out.println(s); output.append(s); }
the while loop condition has read line double reading every time in loop.
while ((s = stdinput.readline()) != null) { //s=stdinput.readline(); <- don't need system.out.println(s); output.append(s); }
/nick
Comments
Post a Comment