/**
* Captures the output of a Gradle exec command.
* ####Example:
* ```
* tasks {
* register<Task>("restartAppServer") {
* group = "MyTasks"
* description = "Restarts your local PS app server."
* val output = execWithOutput {
* workingDir(projectDir)
* commandLine("cmd", "/c", "restartAppServer.bat")
* }
* doLast { println(output) }
* }
* }
* ```
*/
fun Project.execWithOutput(spec: ExecSpec.() -> Unit): String = ByteArrayOutputStream().use { outputStream ->
exec {
standardOutput = outputStream
spec()
}
outputStream.toString()
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter