0

I am writing an GUI interface program for a command line program with a REPL (think like bash or gnuplot), from now on called tlmgr. The main thread does the GUI (scalafx) thingy, another thread starts tlmgr and connects stdin/stdout/stderr:

val procIO = new ProcessIO(inputFn(_), outputFn(_), errorFn(_))
val processBuilder: ProcessBuilder = Seq("tlmgr", "shell")
process = processBuilder.run(procIO)

The outputFn, and errorFn use a BufferedReader from the InputStream pass to the ProcessIO:

val reader = new BufferedReader(new InputStreamReader(stdOut))

The outputFn does basically read in a loop the output and puts it into a SyncVar[String]:

while (true) {
    line = reader.readLine
    outputString.put(line)
}

(with a bit more details of course).

From the main thread I send a string to tlmgr and read the output until the prompt arrives again.

def get_output_till_prompt() = {
  ...
  while (!found) {
    result = outputString.take()
    if (result == "PROMPT")
      found = true

(again of course with bit more details).

Now that works without any problems and I can interact in many ways, lots of things work smoothly.

Until the following happens: I send a certain string to tlmgr, then tlmgr does several things internally (it is a perl program), and then tlmgr in turn calls external programs to do some work. After this tlmgr happily outputs PROMPT again, BUT it is now seen by the reader. It seems to be completely lost in the off.

Also, further communication with tlmgr looks bogged, no reaction whatsoever, and everything hangs.

Are there any caveats with this setup?

Full code: https://github.com/TeX-Live/tlcockpit

Norbert Preining
  • 237
  • 1
  • 11

1 Answers1

0

I'm answering my own question because I found the problem. A piece of code threw and exception in a subsidiary thread and interestingly this was not signaled anywhere, no interruption whatsoever. Adding try and catch around the whole thread part revealed the bug.

I'm still surprised that the program continued working with the uncaught exception, though.

Norbert Preining
  • 237
  • 1
  • 11