Command line task

The execResult is null because the task hasn’t ran yet.

Printing the standardOutput/input they way you do it is not quite right because:

  • you’re printing it at configuration phase

  • printing it only prints the string representation of the default stream (by default, Gradle uses System.out). If you want to get hold of the output, assign brand new ByteArrayOutputStream. Take a look at the example:

task foo(type: Exec) {
  commandLine = //
      //store the output instead of printing to the console
  standardOutput = new ByteArrayOutputStream()
      //extension method foo.output() can be used to obtain the output String
  ext.output = {
    return standardOutput.toString()
  }
  }
  task showFooOutput(dependsOn: foo) {
  doLast {
    println "Foo's output: ${foo.output()}"
  }
}

Hope that helps!