如何在ant脚本中检查dos环境属性是否设置 [英] how to check whether dos environment property is set or not in ant scripting

查看:193
本文介绍了如何在ant脚本中检查dos环境属性是否设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ant脚本


    <property environment="env">
    <if> <equals arg1="${env.PARA} arg2=""/>
    <then>
        <property name="${env.PARA}" value="abc"/>
    <then>
    <if>

    <echo message="${env.PARA}">

输出是


${env.PARA}

预期的输出是


abc

我没有在dos中定义环境变量 PARA 如何获得预期的输出。

I have not defined the environment variable PARA in dos. How to get the expected output.

注意:我在Windows 7中使用ant 1.8.2和antcontrib

Note : I am using ant 1.8.2 and antcontrib in windows 7

推荐答案

以下是有条件地设置属性的ANT方式。

The following is the "ANT way" to conditionally set properties.

<project name="test" default="run">

    <property environment="env"/>

    <target name="check-prop" unless="${env.PARA}">
        <property name="env.PARA" value="abc"/>
    </target>

    <target name="run" depends="check-prop">
        <echo message="${env.PARA}"/>
    </target>

</project>



测试



我是一个linux用户,但是它应该在Windows上工作。

Testing

I'm a linux user, however, it should work the same on windows.

$ ant
Buildfile: /home/mark/tmp/build.xml

check-prop:

run:
     [echo] abc

BUILD SUCCESSFUL



环境变量



environment variable

$ (export PARA="hello world"; ant)
Buildfile: /home/mark/tmp/build.xml

check-prop:

run:
     [echo] hello world

BUILD SUCCESSFUL

这篇关于如何在ant脚本中检查dos环境属性是否设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆