I try to start a GitLog command via Processbuilder in Java.
GitLog Command :
git --git-dir=C:/Users/User/Code/code1/git/.git log --pretty=format:"%H \"%an\" %ad \"%s\"" --numstat --date=short
This is my code. The Path is the path to the git dir. I hardcoded the gitpath to the git dir for testing.
public void createGitLog( Path path ) {
try
{
String gitpath = "--git-dir=C:/Users/User/Code/code1/git/.git";
String options = "--pretty=format:\"%H \\\"%an\\\" %ad \\\"%s\\\"\" --numstat --date=short";
ProcessBuilder builder = new ProcessBuilder("git", gitpath, "log", options );
Process process = builder.start();
builder.redirectOutput(ProcessBuilder.Redirect.to( path.resolve("gitlog.dat").toFile() ) );
int exitValue = process.waitFor();
if ( exitValue != 0 )
{
// throw
}
}
catch (IOException e) {
}
}
If i try this command in the cmd it works, but in Java I get always the exitcode 128.
What is the Problem with this process ?
That what works in my case to run commands in terminal:
you can also use on ProcessBuilder
directory()
if you want to start process from specific dir;