I want to program a chess GUI in Java. The user can enter a move and then I want the program to make a move. Therefore I'll use an UCI (Universal Chess Interface). An UCI is a terminal/command line application (I'm using Mac OS X and Terminal) that calculates the best move in a position. Now what I need to do is write and read to this terminal application.
For example:
I want the best move for a certain position, so I type:
"go" (calculates the best move)
Let's say I get this answer:
"e2e4" (means moving the Pawn (that's a piece in chess) from the e2-square to the e4-square)
Now I need to read that "e2e4" and then ask the user for his next move. So i kinda need to loop through these steps all the time until there is a checkmate: 1. Ask for a move 2. Calculate best response
I've already seen a lot of other StackOverflow questions asking the same question: How to run a command and get its output in Command Line/Terminal. But all answers only use one command, as for instance runtime.exec("ls"); But that's only one command. What I want is to enter a command, get the response, execute another command and so on, so basically I need to communicate with Mac OSX' Terminal app (alternating input and output). How do I accomplish that in Java?