8

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?

Cuga
  • 17,668
  • 31
  • 111
  • 166
  • 'C:\test\foo' isn't a relative path. You may need to correct the question. – Gleb May 22 '09 at 21:58
  • Edited. In the end I need this to work with a relative path. The fact that this doesn't work blows my mind. – Cuga May 22 '09 at 22:00

3 Answers3

6

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
  • 63,927
  • 12
  • 112
  • 147
3

I ended up sticking with this:

<exec executable="${basedir}\myexefile.exe}" />
Cuga
  • 17,668
  • 31
  • 111
  • 166
1

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.

Jonathan Holloway
  • 62,090
  • 32
  • 125
  • 150