I have a Java application that launches a Python process. The Python process opens up a socket and listens for incoming data that is sent to it. Python will make prints to the screen throughout its lifetime that my Java app needs to be able to read. My Java code is as follows:
Runtime runTime = Runtime.getRuntime();
Process proc = runTime.exec(command, null, dir);
reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
while ((line = reader.readLine()) != null)
{
System.out.println(line);
}
This works for me in general, but as soon as I have my Python socket listen, I no longer receive anymore of the input stream. As shown below, when I comment out my receive within the Python script, my Java application will receive both prints.
print "socket waiting to receive"
#data, addr = sock.recvfrom(self.BUFFER_SIZE) # this line causing problems
print "socket received data"
If I uncomment the receive, I no longer get ANY prints within Java. I don't even get the print that occurs before the blocking recvfrom statement. If I run the script from the command line directly, I still get the "socket waiting to receive" and will get the "socket received data" print whenever I receive data.