开发者

Running a BAT file from ANT

I have gone through number of posts on the very foru开发者_如何学Gom but couldn't sort it out. I am trying to run a BAT file from ANT script. The folder hierarchy is like this

- Project
| - build.xml
| - build-C
| | - test.bat

The ANT file that i wrote so for is

<project name="MyProject" basedir=".">
    <property name="buildC" value="${basedire}\build-C" />

    <exec dir="${buildC}" executable="cmd" os="Windows XP">
        <arg line="/c test.bat"/>
    </exec>
</project>

The bat file content is

echo In Build-C Test.bat

It says that build failed .. :s i dun know what wrong am i doing ?


<property name="buildC" value="${basedire}\build-C" />

This should be ${basedir} I guess? Use

<echo>${buildC}</echo>

to make sure the dir is correct.

And shouldn't

<exec dir="${buildC}" executable="test.bat" os="Windows XP" />

do the job?


Hopefully this will help expand on the already given/accepted answers:

I suggest executing cmd with the batch script as a parameter:

<exec failonerror="true" executable="cmd" dir="${buildC}">
  <arg line="/c &quot;${buildC}/test.bat&quot;"/>
</exec>

Not sure if it is necessary to use the absolute path &quot;${buildC}/test.bat&quot; since dir is specified, but I put it just in case. It might be enough to use /c test.bat.

My project executes a batch script on Windows operating systems & a shell script on all others. Here is an example:

<target name="foo">
  <!-- properties for Windows OSes -->
  <condition property="script.exec" value="cmd">
    <os family="windows"/>
  </condition>
  <condition property="script.param" value="/c &quot;${basedir}/foo.bat&quot;">
    <os family="windows"/>
  </condition>
  <!-- properties for non-Windows OSes -->
  <property name="script.exec" value="sh"/>
  <property name="script.param" value="&quot;${basedir}/foo.sh&quot;"/>

  <echo message="Executing command: ${script.exec} ${script.param}"/>

  <exec failonerror="true" executable="${script.exec}" dir="${basedir}">
    <arg line="${script.param}"/>
  </exec>
</target>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜