這就是情況。我創建了一個UI,這將允許使用遺傳編程系統(ECJ)更容易使用。Java Runtime.exec()運行一個java程序
當前您需要在ECJ文件夾內運行命令提示符,並使用與此類似的命令來執行參數文件。
java ec.Evolve -file ec\app\tutorial5\tutorial5.params
凡tutorial5的完整路徑是
C:\Users\Eric\Documents\COSC\ecj\ec\app\tutorial5\tutorial5.params
和命令提示必須從
C:\Users\Eric\Documents\COSC\ecj
我的程序使用戶選擇一個.params文件(它位於要執行在ecj子目錄中),然後使用Runtime.exec()執行
java ec.Evolve -file ec\app\tutorial5\tutorial5.params
我有什麼到目前爲止
// Command to be executed
String cmd = "cd " + ecjDirectory;
String cmd2 = "java ec.Evolve -file " + executeDirectory;
System.out.println(cmd);
try {
Process p = Runtime.getRuntime().exec(
new String[]{"cmd.exe", "/c", cmd, cmd2});
BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
statusTF.append(r.readLine());
p.waitFor();
} catch (IOException | InterruptedException ex) {
System.out.println("FAILED: " + ex.getMessage());
statusTF.append("Failed\n");
}
目前,它輸出的更改目錄命令,但沒有別的。 可以這樣做嗎?
程序是否完成時出現錯誤或只是掛起exec()命令之後? – Dave
try語句無錯誤地結束 – George