How does Exec type task find an executable

(Aver Mimas) #1


I noticed that when I configure an Exec type task, I need to specify the extension of the executable file. Otherwise Gradle can’t find the file to execute. It does not happen to standard windows commands (tested on Windows OS only). Even though I can run that executable from command line manually without specifying the extension (the location is in environment path), in Gradle I need to specifically add the extension of the file to either “commandLine” or “executable” parameter.

(Luke Daley) #2

What you’re experiencing is the difference the “shell” makes. It’s the “Windows Shell” that provides the behaviour of resolving the executable sans extension, along with other features such as IO redirection and so forth.

The ‘Exec’ task does not create a shell. It just launches the process “directly”. For the purposes of this discussion, it’s the same as using the ‘Process’ class that is part of the JDK. If you want to dig into the implications of this further, you could read some articles about using this JDK API to launch processes on Windows. There are many such articles online. 

(Aver Mimas) #3

Thanks Luke for your reply. I’ll take a look at the JDK API when I get a chance. But, but it was just confusing because I was able to call another program without specifying the extension. For example, this worked perfectly fine.

task openDB2cmd (type: Exec) {

commandLine ‘db2cmd’ }

But for another program I had to specify the extension of the program, even though both programs can be accessed via environment path. It just seemed inconsistent and not sure why.