Works for me (edited for brevity):
[binky] ant -f test.xml runIfNT
touchit:
[touch] Creating D:\dianeh\src\main\foo_Windows NT
runIfNT:
This is running because the OS is Windows NT
[binky] ant -f test.xml runIfUnix
touchit:
runIfUnix:
[binky] ant -Dos.name=unix -f test.xml runIfUnix
touchit:
[touch] Creating D:\dianeh\src\main\foo_unix
runIfUnix:
This is running because the OS is unix
My targets are:
<target name="touchit">
<touch file="foo_${os.name}"/>
<available file="foo_Windows NT" property="NT"/>
<available file="foo_unix" property="unix"/>
</target>
<target name="runIfNT" depends="touchit" if="NT">
<echo message="This is running because the OS is ${os.name}"/>
</target>
<target name="runIfUnix" depends="touchit" if="unix">
<echo message="This is running because the OS is ${os.name}"/>
</target>
Diane
--- John Hempe <[EMAIL PROTECTED]> wrote:
> Forgive me if I'm missing the obvious, but:
>
> How do I detect what OS I am running under in Ant? Yes, I know about
> the
> property "os.name", but it doesn't seem like Ant allows you to test the
> *content* of this (or any other) property for purposes of branching
> behavior--only whether or not the property is set.
>
> I've been trying contortions like:
> <touch file=".build_OS_is_${os.name}"/>
> <available file=".build_OS_is_Windows NT"
> property="build.os.is.NT"/>
> <available file=".build_OS_is_SunOS"
> property="build.os.is.SunOS"/>
>
> But this doesn't work because Available checking is obviously being done
> before the touch, must be a "special" task from Ant's runtime point of
> view,
> perhaps because it wants to know all property values before executing
> tasks.
>
>
> Of course, the OS-indicating file is there the *next* time you run Ant,
> but
> this is so ugly I figured I'd just punt and ask. I know that "exec" has
> an
> "os" attribute but others don't. I want to do the seemingly-obvious:
>
> <target name="OSDependentTarget" if="My_OS_is_UNIX">
> </target>
>
> I know I could force the user to specify their OS in a property file,
> but
> Ant's Java runtime already knows. . .I just am not sure how to branch
> based
> on that knowledge.
>
> --John Hempe
>
>
=====
([EMAIL PROTECTED])
__________________________________________________
Do You Yahoo!?
Thousands of Stores. Millions of Products. All in one Place.
http://shopping.yahoo.com/