I want to write a shell command in groovy and execute via gradle. For example, I have this command :
git log tag2 tag1
This lists the commits done in between two tags. I simply want to write this in groovy. Currently, I am writing like :
task show <<
{
def fist = "git log new-tag4 new-tag5"
println("[fist]")
Process process = fist.execute()
println(process.text)
}
This build successfully but doesn't give me the result. Anything I am missing or doing wrong?
First, make sure you are in the right directory:
Process process = fist.execute(null, new File("your git repo"))
Or:
"git log new-tag4 new-tag5".execute(null, new File("C:\Rep9"))
Second, make sure you see everything (stdout, stderr) just in case the command has an issue:
def process=new ProcessBuilder("git log new-tag4 new-tag5").redirectErrorStream(true).directory(new File("your git repo")).start()
process.inputStream.eachLine {println it}
See more at "Executing shell commands in Groovy".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With