Philippe A
Philippe A

Reputation: 1252

Unable to execute a sh file from a Gradle Exec task

I configured this simple Gradle task in a project

task startMyProgram(type: Exec) {
    commandLine "myProgram.sh", "${System.getProperty("argument")}"
}

This sh file is executable (chmod a+x myProgram.sh) and is located in the root folder of the project, from where I run the Gradle command.

When I run the task with ./gradlew startMyProgram -Dargument=foo it fails with the following error message:

Caused by: java.io.IOException: Cannot run program "myProgram.sh" (in directory "/Users/paristote/Work/my-project"): error=2, No such file or directory

I've tried running commands like commandLine "echo", "Hello World" and they work just fine.

Does anybody have a clue why this simple command fails? I'm using Gradle 4.1 if it helps.

Thanks.

Upvotes: 0

Views: 945

Answers (1)

Philippe A
Philippe A

Reputation: 1252

Turns out I needed to configure the task like this:

commandLine "./myProgram.sh", "${System.getProperty("argument")}"

Note the ./ in the executable name.

Upvotes: 1

Related Questions