How do I get the hostname in a cross-platform way?

Erik Hatcher

Ant has a mechanism for gathering environment variables. Unfortunately the hostname environment variable is different on Windows versus Unix boxes, but Ant's property immutability helps us out:

  <target name="set-name">
    <property environment="env"/>
    <property name="env.HOSTNAME" value="${env.COMPUTERNAME}"/>
    <echo message="host = ${env.HOSTNAME}"/>
  </target>
HOSTNAME is the environment variable on Unix platforms (at least on the ones I've used - please alert me if this is not always the case), and COMPUTERNAME on Windows platforms.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact