- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我尝试通过 Java 中的 Processbuilder 启动 GitLog 命令。
GitLog 命令:
git --git-dir=C:/Users/User/Code/code1/git/.git log --pretty=format:"%H \"%an\" %ad \"%s\"" --numstat --date=short
这是我的代码。 Path 是 git 目录的路径。我将 gitpath 硬编码到 git 目录进行测试。
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) {
}
}
如果我在 cmd 中尝试这个命令,它会起作用,但在 Java 中我总是得到退出代码 128。
这个过程有什么问题?
最佳答案
在我的例子中,在终端中运行命令的方法是:
"/bin/bash" - path to your bash
"-c" - states that next param is command
"command" - full command you want to execute from terminal (like
git log --pretty=format:"%H \"%an\" %ad \"%s\"" --numstat --date=short
)
String command = "git " + gitpath + " log " + options;
ProcessBuilder builder = new ProcessBuilder("/bin/bash" , "-c" , command);
如果您想从特定目录启动进程,也可以在 ProcessBuilder directory()
上使用;
.directory(new File("C:/Users/User/Code/code1/git/"))
关于java - 使用 Java Process Builder 启动 GitLog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44407664/
我尝试通过 Java 中的 Processbuilder 启动 GitLog 命令。 GitLog 命令: git --git-dir=C:/Users/User/Code/code1/git/.gi
我是一名优秀的程序员,十分优秀!