As the title says, I use Runtime.getRuntime().exec
to execute git commit -m XXX
command.
Unfortunately, it returns the unmormal exitcode with 1 (btw,the right code is 0).
I try to type the command on the command line,the commit command is working OK.
Anybody knows where the problem is?
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;
}
Outputs below:
git commit -m test commit msg
exitcode = 1