You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by al...@upandcoming.co.uk on 2001/03/09 15:53:07 UTC

conditional if statement

Hello,
Could you tell me if there is a way to execute a target, such that ${os.name}!="Windows NT"? The current if statement in a target can only be used if a property has been set, however, it does not allow the evaluation of a statment.
                   Thanks,
                          Alan

Laters,
        Alan


-----

Be passionate about your email
Just click here: http://another.com

Re: conditional if statement

Posted by Bill Burton <bi...@progress.com>.
Hello Alan,

You will have to write a task to do this or, you could set a property when
Ant starts up that would accomplish the same thing.

Assuming Ant 1.3, create a batch file antrc_pre.bat with something like
the following contents:
    if "%OS%" == "Windows_NT" set ANT_OPTS=%ANT_OPTS% -Dos.windows.nt=true
    if not "%OS%" == "Windows_NT" set ANT_OPTS=%ANT_OPTS%
-Dos.windows.9x=true
    set ANT_OPTS=%ANT_OPTS% -Dos.windows=true

Put the antrc_pre.bat in the directory pointed to by the %HOME% enviroment
variable (assumes Windows NT/2000).  The ant.bat script will run
antrc_pre.bat every time it starts up.  Anything in %ANT_OPTS% will be
passed to Ant on the command line.

If you are using Ant 1.3, you could use the environment attribute of the
<property> task to load the environment into Ant.  Then you could check
for the presense of a Windows specific variable like COMSPEC using,
if="env.COMSPEC" or unless="env.COMSPEC".  This would be fine if you don't
care about NT/2000 vs. 9x versions.

These are all hacks that may or may not work for you.  A task is still the
cleanest way to go and would not depend on any startup settings being
present to get the desired behavior.

-Bill

alan@upandcoming.co.uk wrote:
> 
> Hello,
> Could you tell me if there is a way to execute a target, such that ${os.name}!="Windows NT"? The current if statement in a target can only be used if a property has been set, however, it does not allow the evaluation of a statment.
>                    Thanks,
>                           Alan
> 
> Laters,
>         Alan