Skip to content

Instantly share code, notes, and snippets.

@comdotlinux
Created November 26, 2022 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save comdotlinux/65a9e78926b517dc849c3c192db7d2d0 to your computer and use it in GitHub Desktop.
Save comdotlinux/65a9e78926b517dc849c3c192db7d2d0 to your computer and use it in GitHub Desktop.
Get the Output of an External Command into an variable for further use.
import java.io.ByteArrayOutputStream
tasks.register("gitCommit") {
group = "com.linux"
description = "Get The last git commit"
doLast {
val output = ByteArrayOutputStream().let { os ->
exec {
commandLine("/usr/bin/git rev-parse --verify HEAD".split(" "))
standardOutput = os
}
os.toString()
}
println(output)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment