You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Ramu Sethu <sr...@yahoo.co.in> on 2008/02/26 15:09:36 UTC

env.COMPUTERNAME not working in linux

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

Re: env.COMPUTERNAME not working in linux

Posted by Peter Reilly <pe...@gmail.com>.
>From a console, run the command "env" to see the environment variables.

On unix/linux the env variable "HOSTNAME" is normally used to get the
name of the computer.

(Although on my current machine this is "localhost.localdomain").

Peter

On Tue, Feb 26, 2008 at 2:09 PM, Ramu Sethu <sr...@yahoo.co.in> 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
>

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


Re: env.COMPUTERNAME not working in linux

Posted by Vijay Aravamudhan <av...@gmail.com>.
> Is COMPUTERNAME only for windows? Is there any workaround to print the
> hostname(Linux)?

The end of that statement is misleading - are you looking for the hostname or the host OS? Or is your machine named 'Linux'?

Vijay



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.
>
>   

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


Re: env.COMPUTERNAME not working in linux

Posted by Gilbert Rebhan <an...@schillbaer.de>.
Hi,

Samuel Monsarrat wrote:
>> Is COMPUTERNAME only for windows? Is there any workaround to print the
>> hostname(Linux)?
>>   
> Indeed yes COMPUTERNAME is a Windows standard env variable that does not
> exist on linux. env.xxxx is dangerous in a multi-os build system, as you
> are accessing the underlying operating system variables, you are
> therefore no longer platform independent.

<exec executable="hostname" outputproperty="computer.hostname"/>

will work on both, linux and windows

Regards, Gilbert


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


Re: env.COMPUTERNAME not working in linux

Posted by Samuel Monsarrat <sa...@kelis.fr>.
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.
> Is COMPUTERNAME only for windows? Is there any workaround to print the
> hostname(Linux)?
>   
Indeed yes COMPUTERNAME is a Windows standard env variable that does not 
exist on linux. env.xxxx is dangerous in a multi-os build system, as you 
are accessing the underlying operating system variables, you are 
therefore no longer platform independent.

You can get the hostname under linux by running the following command:
uname -n

so you should be able to retrieve the hostname with something like :
<if><equals arg1="${os.name}" arg2="Linux"/>
    <then>
        <exec executable="uname" outputproperty="computer.hostname">
            <arg line="-n"/>
        </exec>
    </then>
    <else>
       <property name="computer.hostname" value="${env.COMPUTERNAME}"/>
    </else>
</if>

> We don't make any changes in the ant script when running in Linux.
>   
Well you will have to !

Samuel.


Re: env.COMPUTERNAME not working in linux

Posted by David Weintraub <qa...@gmail.com>.
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>
        <condition property="hostname" value="${env.COMPUTERNAME}">
            <isset property="env.COMPUTERNAME"/>
        </condition>
        <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;/>
</target>


On Tue, Feb 26, 2008 at 9:09 AM, Ramu Sethu <sr...@yahoo.co.in> 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
qazwart@gmail.com

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