My Java application has to work like this:
not sure if you still have the problems, in any case, it might contribute to other people.
ExpectJ is indeed the Java implementation of Unix expect. and you should definitely buy the "explore expect book" then look into it, it is worth it.
For your question: when you spawn a process, you listen to the return output, match it to a prompt, then send some command. if you want to analyze the output, you buffer that output, and do some actions before the next send()
to do so, you need to use the interact() method of the spawn class you used. http://expectj.sourceforge.net/apidocs/index.html
and for interact and how it works: http://oreilly.com/catalog/expect/chapter/ch03.html look for this part: "The interact Command"
You should use ExpectJ, a Java implementation of the Unix expect utility.