我正在尝试找到一种方法来在我的java程序(国际象棋引擎)和外部程序(国际象棋gui)之间建立基于stdout的通信。重要的是要注意外部程序正在启动我的java-app,并使用一个执行.jar文件的bash脚本。 java-app应该能够通过stdout向外部程序发送命令。目前,只有从外部程序到java的通信才有效。 这就是我试过的:
try {
log = new FileWriter("log.txt");
} catch (IOException e) {
System.out.println("IOException on initializing FileWriter 'log'.");
}
while (true) {
try {
stringInput = input.readLine();
} catch (IOException ex) {
System.out.println("IOException on reading Buffered Reader 'input'.");
}
if (stringInput != null){
try {
log.write(stringInput + "\n");
} catch (IOException ex){
System.out.println("IOException on writing to FileWriter 'log'.");
}
switch (stringInput){
case "uci\n":
System.out.println("uciok");
break;
}
} else {
break;
}
}
我希望java程序将传入的命令存储在log.txt文件中,而我应该能够在外部程序的调试控制台中看到来自java-app的命令。
log.txt确实存储了传入的命令。 但是,外部程序收到的java-app没有输出的痕迹。