I am trying to communicate between a process in my java program and an external python script that is called by the java program. The problem arises that my java program only receives the output of the python program after it has terminated. This means I cannot have a duplex "conversation" between the processes, which is my goal. Here is my python code:
for i in range(3):
print("hello"); #send hello to java
line = sys.stdin.readline(); #read read response from java
and my java code:
String line;
Process external = Runtime.getRuntime().exec(execStr);
BufferedReader in = new BufferedReader(new InputStreamReader(external.getInputStream()));
PrintStream out = new PrintStream(external.getOutputStream(),true);
while ((line = in.readLine)) != null){//while python has not yet terminated
if (line.length > 0){ // if not a bogus line
handleLine();
sendResponse();
}
}
The Java then hangs on the next readLine, because it never receives a next output from the python.
Thanks for your help :)