我正在使用Java作为国际象棋的前端AI我正在写。 Java处理所有图形,然后使用几个命令行参数执行一些C语言。有时C将永远不会完成,并且不会回到Java。我找到了发生这种情况的案例,并用.exe和java来测试它们。当我拿出java时,这些情况每次都有效。我不确定该从哪里出发。下面是一些代码,我认为是初步认识,以及整个项目作为https://github.com/AndyGrant/JChess从Java执行C奇怪的错误
try{
Process engine = Runtime.getRuntime().exec(buildCommandLineExecuteString(lastMove));
engine.waitFor();
int AImoveIndex = engine.exitValue();
String line;
BufferedReader input = new BufferedReader(new InputStreamReader(engine.getInputStream()));
while ((line = input.readLine()) != null)
System.out.println(line);
input.close();
if (AImoveIndex == -1){
activeGame = false;
System.out.println("Fatal Error");
while (true){
}
}
else{
JMove AIMove = JChessEngine.getAllValid(types,colors,moved,lastMove,!gameTurn).get(AImoveIndex);
AIMove.makeMove(types,colors,moved);
lastMove = AIMove;
validMoves = JChessEngine.getAllValid(types,colors,moved,lastMove,gameTurn);
}
waitingOnComputer = false;
parent.repaint();
}
catch(Exception e){
e.printStackTrace();
}
无法分辨您发布的内容。不愿意通读该项目。 – duffymo
我在使用java的RunTime执行C程序时正在寻找可能的错误。 – AndrewGrant
如果“C永远不会完成”,你能证明你的C代码不会陷入某个无限循环吗?如果你在C程序返回的'main'函数之前放置'print'语句,是否打印?仅仅因为你手动给C程序提供了正确的输入并且它终止了并不意味着C程序应该在与Java程序集成时终止。例如,您的Java程序可能会错误地格式化输入。我不会马上说,你在使用Runtime时会出现一些奇怪的错误。 – user2570465