Java/Python: Integration, problem with looping updating text

Posted by Jivings on Stack Overflow See other posts from Stack Overflow or by Jivings
Published on 2010-05-06T09:39:06Z Indexed on 2010/05/21 15:00 UTC
Read the original article Hit count: 147

Filed under:
|

Hello! Basically I have a script in Python that grabs the text from an open window using getWindowText() and outputs it to the screen. The python loops so as the text in the window changes, it outputs the changes, so the output of the python will always be up to date with the window text.

I'm trying to access this text in my Java program by executing the python script as a process and reading the text it outputs using a buffered reader.

For some reason this works fine for the first block of text, but will not read any more after this, it wont read any updates to the text as the python outputs it.

Can someone shed some light on this? I'm about to try and use Jython, but I'd really like to know what the problem is here...

try {
  Runtime r = Runtime.getRuntime();
  Process p = r.exec("cmd /c getText.py");
  BufferedReader br = new BufferedReader(
                                new InputStreamReader(p.getInputStream()));
  int line;
  while (true) {
    line = br.read();
    System.out.print((char) line);
  }
} catch (Exception e) {
    e.printStackTrace();
}

© Stack Overflow or respective owner

Related posts about java

Related posts about python