ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ken Rider" <Ken.Ri...@intelliden.com>
Subject RE: Hostname in ant
Date Wed, 25 Aug 2004 14:40:45 GMT
Or...

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

    <scriptdef name="getLocalHost" language="javascript">
         <attribute name="prefix"/>
         <![CDATA[
             host = java.net.InetAddress.getLocalHost();
 
project.setNewProperty(attributes.get("prefix")+"name",host.getHostName(
));
 
project.setNewProperty(attributes.get("prefix")+"ip",host.getHostAddress
());
         ]]>
    </scriptdef>

    <target name="testGetLocalHost">
        <getLocalHost prefix="host."/>
        <echoproperties prefix="host"/>
    </target>

</project>

-----Original Message-----
From: Erik Hatcher [mailto:erik@ehatchersolutions.com] 
Sent: Wednesday, August 25, 2004 5:41 AM
To: Ant Users List
Subject: Re: Hostname in ant

On Aug 24, 2004, at 4:36 PM, Anderson, Rob (Global Trade) wrote:
> Or if $HOSTNAME is set in your environment, you could use....
>
> <property environment="env"/>
>
> and refer to the hostname as "${env.HOSTNAME}".

On Windows, however, HOSTNAME is not set.  Here's a nice trick that 
gets it on 'nix and Windows:

     <property environment="env"/>
     <property name="env.COMPUTERNAME" value="${env.HOSTNAME}"/>

Use ${env.COMPUTERNAME} where the host/computer name is needed.

Good ol' property immutability!

	Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org




---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Mime
View raw message