簡體   English   中英

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進程在同一個目錄中運行,這可能會導致問題,從而導致錯誤輸出。 如果您從第一個進程讀取錯誤流,您將看到如下內容:

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.

如果你在開始第二個之前等待第一個完成,那應該有效。 像這樣的東西:

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()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM