Exec task issues/details?

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!

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.

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.

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

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!

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’ }