开发者

Is there a way to have Ant create a shell or batch runtime script?

开发者 https://www.devze.com 2023-01-20 08:26 出处:网络
Is there a way to have Ant create a runtime shell or batch runtime script in开发者_StackOverflow社区stead of having to manually create the script myself.

Is there a way to have Ant create a runtime shell or batch runtime script in开发者_StackOverflow社区stead of having to manually create the script myself.

It would be similar to the functionality of link text


Yes it can be done. Here's a simple example (your link is not working right now ... sourceforge error thrown). The basic idea is to write the file using the echo task, then run it using the exec task:

<property name="myls" value="myls.sh" />
<echo file="${myls}">
ls
</echo>
<exec executable="sh">
    <arg value="${myls}"/>
</exec>

When run gives the following, as the working directory only contains the build file and the script:

Buildfile: build.xml
     [exec] build.xml
     [exec] myls.sh

This is of course unix-specific, but you could do similar equally well on other systems - for windows you'd change the executable to cmd I believe. You can take this further and pass arguments to your new script too if needed. For example:

<property name="myls" value="myls.sh" />
<echo file="${myls}">
ls $@
</echo>
<exec executable="sh">
    <arg value="${myls}"/>
    <arg value="b*"/>
</exec>

When run now only sees the build file:

Buildfile: build.xml
     [exec] build.xml
0

精彩评论

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