I've a Java program to call a python script. I've used exec method. Please find the code snippet below:
Python program (which is to gather a portion of text from wikipedia), when run separately, gives me proper output. When called from Java, I'm not getting the complete output from python program.
I checked the status of BufferedReader Object using ready() method ( as explained here, and the code entered into infinite loop.
I think others also have faced similar problems-https://stackoverflow.com/a/20661352/3409074
Can anyone help 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);
}