# How does Exec type task find an executable

**URL:** <https://discuss.gradle.org/t/how-does-exec-type-task-find-an-executable/5283>\
**Category:** Old Forum Archive\
**Created:** [March 22, 2015, 1:57am UTC](https://discuss.gradle.org/t/how-does-exec-type-task-find-an-executable/5283 "2015-03-22T01:57:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aver\_Mimas](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@Aver\_Mimas](https://discuss.gradle.org/u/Aver_Mimas)\
**Post date:** [March 22, 2015, 1:57am UTC](https://discuss.gradle.org/t/how-does-exec-type-task-find-an-executable/5283/1 "2015-03-22T01:57:00Z")

</div>

Hello,

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.

---

<div class="post-metadata">

**Author:** ![luke\_daley](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/luke_daley/32/9890_2.png) [@luke\_daley](https://discuss.gradle.org/u/luke_daley)\
**Post date:** [March 24, 2015, 2:11am UTC](https://discuss.gradle.org/t/how-does-exec-type-task-find-an-executable/5283/2 "2015-03-24T02:11:00Z")

</div>

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.&nbsp;

---

<div class="post-metadata">

**Author:** ![Aver\_Mimas](https://avatars.discourse-cdn.com/v4/letter/a/43a26b/32.png) [@Aver\_Mimas](https://discuss.gradle.org/u/Aver_Mimas)\
**Post date:** [March 24, 2015, 4:11pm UTC](https://discuss.gradle.org/t/how-does-exec-type-task-find-an-executable/5283/3 "2015-03-24T16:11:00Z")

</div>

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.
