/** * 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() }