Как видно из заголовка, я использую Runtime.getRuntime().exec
для выполнения git commit -m XXX
команды.
К сожалению, он возвращает нестандартный код выхода с 1 (кстати, правильный код 0).
Я пытаюсь набрать команду в командной строке command команда commit работает нормально.
Кто-нибудь знает, где проблема?
public static int commit(String dir,String commitMsg) {
String command = "git commit -m " + commitMsg;
exitCode = ProcessUtil.safeSyncRun(command, dir);
System.out.println(command + " exitcode = " + exitCode);
return exitCode;
}
public static int safeSyncRun(String command, String workingDir) {
Process process;
int exitValue = -1;
try {
process = Runtime.getRuntime().exec(command, null, new File(workingDir));
process.waitFor();
exitValue = process.exitValue();
} catch (IOException | InterruptedException e) {
System.out.println("exception : " + e);
}finally{
process = null;
}
return exitValue;
}
Выходы ниже:
git commit -m test commit msg
exitcode = 1