views:

1179

answers:

3

I have the following snippet in my Ant script. It executes just fine:

<exec executable="C:\test\foo\programName.exe" />

But then when I try to execute it by setting the directory, like so:

<exec executable="programName.exe"
  dir="C:\test\foo\" />

I get:

Execute failed: java.io.IOException: Cannot run program "programName.exe" (in directory "C:\test\foo"): CreateProcess error=2, The system cannot find the file specified

Please help! Why is it not working when the directory is specified separately?

+1  A: 

Try this:

<property name="prog.dir" value="C:/test/foo" />
<exec executable="${prog.dir}/programName.exe"/>

It appears that the directory from which you execute the program must be in your build path.

Jon
A: 

Add the resolveexecutable attribute:

<exec executable="programName.exe" 
  resolveexecutable="true"
  dir="C:\test\foo\" />

resolveexecutable When this attribute is true, the name of the executable is resolved firstly against the project basedir and if that does not exist, against the execution directory if specified. On Unix systems, if you only want to allow execution of commands in the user's path, set this to false. since Ant 1.6 No, default is false

Mads Hansen
A: 

I ended up sticking with this:

<exec executable="${basedir}\myexefile.exe}" />
Cuga