Alex
Alex

Reputation: 5904

Gradle: How to pipe into a Exec task

I need to provide a default "yes" to a command I try to execute with Gradle.

So the moment I run:

./gradlew mytask

it should execute something like:

yes | <path-to-script-or-command>

How would I do that?

Upvotes: 2

Views: 733

Answers (1)

Bj&#248;rn Vester
Bj&#248;rn Vester

Reputation: 7600

If there is only one input to the command, you can do:

task mytask(type: Exec) {
  commandLine "my-command"
  standardInput = new ByteArrayInputStream("yes".getBytes())
}

If you need it to be interactive, use standardInput = System.in.

I am not aware of a way to provide multiple fixed inputs though (e.g. the command first asks for one input, and after that another).

Upvotes: 3

Related Questions