ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "David Weintraub" <>
Subject Re: env.COMPUTERNAME not working in linux
Date Tue, 26 Feb 2008 19:53:25 GMT
There really isn't a standard environment variable name for storing
the system name on the various flavors of Unix. This is usually set
when users log in. Some shells do set the environment variable
HOSTNAME, but not all. Even on Windows, the environment variable
COMPUTERNAME cannot be trusted because it can changed by the user.

On Linux, the environment variable HOSTNAME is set by the default
shell (BASH), but not by other shells like Bourne, Csh, or Kornshell.
You could simply make it a policy that HOSTNAME should be set on Unix
logins in order for your build to work.

This will find the hostname whether it is set in COMPUTERNAME (as on
Windows) or HOSTNAME (as normally done on Linux/Unix):

<target name="getname">
        <property environment="env"/>
        <condition property="hostname" value="${env.HOSTNAME}">
            <isset property="env.HOSTNAME"/>
        <condition property="hostname" value="${env.COMPUTERNAME}">
            <isset property="env.COMPUTERNAME"/>
        <fail unless="hostname"
            message="You must set the environment variable HOSTNAME or
COMPUTERNAME to use this build script"/>
        <echo message="The computer's name is &quot;${hostname}&quot;/>

On Tue, Feb 26, 2008 at 9:09 AM, Ramu Sethu <> wrote:
> Hi
>  We have a build script which runs in both windows and Linux m/c. Recently i
>  added property to print the computer name of the m/c in which the script
>  runs.
>  In windows everything is fine. Ant sets the property  to the hostname in
>  windows. But in Linux it prints the hostname like "${env.COMPUTERNAME}".
>  Value is not printed.
>  Is COMPUTERNAME only for windows? Is there any workaround to print the
>  hostname(Linux)?
>  We don't make any changes in the ant script when running in Linux.
>  --
>  Thank you
>  Ramu S

David Weintraub

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

View raw message