ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stefan Bodewig <>
Subject Re: Environment Variable Retrieval in Future Ant Versions
Date Tue, 05 Mar 2002 12:08:25 GMT
On Tue, 5 Mar 2002, Christoph Thommes <> wrote:
> I would like to read an environment variable on a Windows machine,
> for example SystemRoot.
> Since the environment variable retrieval in Ant is case-sensitive, I
> cannot be sure that
> <property environment="env" />
> <property name="SystemRoot" value="${env.SystemRoot}" />
> will always return a value. I, therefore, would like to have a
> default value, if no value is available.

Simply assign your default value to env.SystemRoot after the
<property environment="env" /> - if no environment varibale of that
name has been defined, Ant will set your defauklt value.  Otherwise it
won't override the original value.

> Is the condition statement going to work the same way in future
> versions of Ant (1.5+)?


But you could do

<condition property="SystemRoot" value="${env.SystemRoot}">
  <isset property="env.SystemRoot" />
<property name="SystemRoot" value="your-default-value" />

taking advantage of <property> not overriding existing properties.

The Ant 1.4.1 way would be

<condition property="SystemRoot" value="${env.SystemRoot}">
    <equals arg1="${env.SystemRoot}" arg2="$${env.SystemRoot}" />
<property name="SystemRoot" value="your-default-value" />

I'd stick with 

<property environment="env" />
<property name="env.SystemRoot" value="your-default-value" />

and use ${env.SystemRoot} through the whole build.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message