Groovy执行一个git shell命令 [英] Groovy execute a git shell command
问题描述
我试图在groovy中执行git shell命令。第一个执行得很好,但第二个返回退出码128:
def workingDir = new File(path / to / dir )
git add。。execute(null,workingDir)
def p =git reset --hard.execute(null,workingDir)
p.text.eachLine {println it}
println p.exitValue()
这段代码有什么问题?
第二个过程在第一个过程完成之前开始。当第二个git进程启动时,git认识到已经有一个git进程在同一个目录下运行,这可能会导致问题,从而导致出错。如果您从第一个进程读取错误流,您将看到如下所示:
致命:无法创建'path / to /dir/.git/index.lock':文件存在。
如果当前没有其他git进程正在运行,这可能意味着
git进程早些时候在此存储库中崩溃。确保没有其他的git
进程正在运行,并手动删除文件以继续。
如果您在开始第二个之前等待第一个完成,那就应该起作用。例如:
pre $ def workingDir = new File(path / to / dir /)
)def p =git add。。execute(null,workingDir)
p.waitFor()
p =git reset --hard.execute(null,workingDir)
p。 text.eachLine {println it}
println p.exitValue()
I'm trying to execute git shell command in groovy. The first is executed well but the second returns the exit code 128:
def workingDir = new File("path/to/dir")
"git add .".execute(null, workingDir)
def p = "git reset --hard".execute( null, workingDir )
p.text.eachLine {println it}
println p.exitValue()
what's the problem with this code?
The second process is starting before the first one completes. When the second git process starts git recognizes that there is already a git process operating in that same directory which could cause problems so it errors out. If you read the error stream from the first process you will see something like this:
fatal: Unable to create 'path/to/dir/.git/index.lock': File exists.
If no other git process is currently running, this probably means a
git process crashed in this repository earlier. Make sure no other git
process is running and remove the file manually to continue.
If you wait for the first one to finish before starting the second one, that should work. Something like this:
def workingDir = new File("path/to/dir/")
def p = "git add .".execute(null, workingDir)
p.waitFor()
p = "git reset --hard".execute( null, workingDir )
p.text.eachLine {println it}
println p.exitValue()
这篇关于Groovy执行一个git shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!