# Exec task issues/details?

**URL:** <https://discuss.gradle.org/t/exec-task-issues-details/6448>\
**Category:** Old Forum Archive\
**Created:** [March 7, 2012, 5:38pm UTC](https://discuss.gradle.org/t/exec-task-issues-details/6448 "2012-03-07T17:38:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![redcoat](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@redcoat](https://discuss.gradle.org/u/redcoat)\
**Post date:** [March 7, 2012, 5:38pm UTC](https://discuss.gradle.org/t/exec-task-issues-details/6448/1 "2012-03-07T17:38:00Z")

</div>

Hi,

Running into some issues using the exec task. I want to run an exe, so I set up the working directory and specified the exe on the command line. It throws an exception saying it can’t find the file in the directory it’s sitting in!

Cause: Cannot run program “xxx.exe” (in directory “C:\sandbox\project1”): CreateProcess error=2, The system cannot find the file

specified Cause: CreateProcess error=2, The system cannot find the file specified

However, it does find it if I use ‘cmd’, ‘/c’, ‘xxx.exe’ as the command line.

I have tried the executable option too, with same issue.

Any ideas why this is the case? Where can I find further details/examples on using the exec task (I looked at the user guide)?

thanks!

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [March 7, 2012, 6:33pm UTC](https://discuss.gradle.org/t/exec-task-issues-details/6448/2 "2012-03-07T18:33:00Z")

</div>

It’s the expected behavior. You have to add ‘cmd’ and ‘/c’ on Windows. Maybe Gradle could do this automatically. I’m not sure of the implications though.

The best source of information for DSL/API question is the [DSL reference](http://gradle.org/docs/current/dsl/org.gradle.api.tasks.Exec.html).

---

<div class="post-metadata">

**Author:** ![redcoat](https://avatars.discourse-cdn.com/v4/letter/r/57b2e6/32.png) [@redcoat](https://discuss.gradle.org/u/redcoat)\
**Post date:** [March 7, 2012, 6:47pm UTC](https://discuss.gradle.org/t/exec-task-issues-details/6448/3 "2012-03-07T18:47:00Z")

</div>

Hi Peter,

The confusing part for me is that this works:

task testExec(type:Exec) {

executable ‘keytool’ }

If I point to my own executable, even if I add the dir to the path, it fails.

---

<div class="post-metadata">

**Author:** ![Peter\_Niederwieser](https://avatars.discourse-cdn.com/v4/letter/p/9f8e36/32.png) [@Peter\_Niederwieser](https://discuss.gradle.org/u/Peter_Niederwieser)\
**Post date:** [March 8, 2012, 5:37am UTC](https://discuss.gradle.org/t/exec-task-issues-details/6448/4 "2012-03-08T05:37:00Z")

</div>

We just pass this on to Java’s ProcessBuilder. So it’s either a Java or a Windows oddity.

---

<div class="post-metadata">

**Author:** ![halljulian](https://sea1.discourse-cdn.com/gradle/user_avatar/discuss.gradle.org/halljulian/32/5284_2.png) [@halljulian](https://discuss.gradle.org/u/halljulian)\
**Post date:** [April 4, 2012, 12:59pm UTC](https://discuss.gradle.org/t/exec-task-issues-details/6448/5 "2012-04-04T12:59:00Z")

</div>

Ya i’ve been having issues with this for months… i haven’t found a solid solution yet. If anyone knows how to deal with this correctly that would be appreciated!

---

<div class="post-metadata">

**Author:** ![ingineering](https://avatars.discourse-cdn.com/v4/letter/i/bc8723/32.png) [@ingineering](https://discuss.gradle.org/u/ingineering)\
**Post date:** [May 8, 2012, 7:36pm UTC](https://discuss.gradle.org/t/exec-task-issues-details/6448/6 "2012-05-08T19:36:00Z")

</div>

Working fine for me on Windows with gradle 1.0-rc-3:

exec {

workingDir ‘baseDir/exeDir’

// Don’t need Windows-style backslashes

commandLine ‘cmd’, ‘/c’, ‘myExe.exe’, ‘arg1’, ‘arg2’ }
