You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Oliver Alth <OA...@de.ibm.com> on 2003/05/26 15:10:04 UTC

Reading OS-Specific Environment Variables

Hello,

I would like to read OS-Specific environment variables using the Ant API.
In the JAVADOC, I found this one:

public void setEnvironment(java.lang.String env)
      the prefix to use when retrieving environment variables. Thus if you
      specify environment="myenv" you will be able to access OS-specific
      environment variables via property names "myenv.PATH" or
      "myenv.TERM".


      Note that if you supply a property name with a final "." it will not
      be doubled. ie environment="myenv." will still allow access of
      environment variables through "myenv.PATH" and "myenv.TERM". This
      functionality is currently only implemented on select platforms. Feel
      free to send patches to increase the number of platforms this
      functionality is supported on ;).
      Note also that properties are case sensitive, even if the environment
      variables on your operating system are not, e.g. it will be
      ${env.Path} not ${env.PATH} on Windows 2000.


Parameters:
      env - prefix

But How can I read out those variables?

Thanks,

Oliver


__________________________________________________________________
IBM Deutschland Entwicklung GmbH, Schönaicher Str. 220, D-71032 Böblingen
eServer Software Management, D4357, Intern: 7103-06, Tel. 902-2790,
Tel.: ++49-(0)7031-16-4280, Fax.: 07031-16-2790
Internet: OALTH@DE.IBM.COM


Re: Reading OS-Specific Environment Variables

Posted by Stefan Bodewig <bo...@apache.org>.
On Mon, 26 May 2003, Oliver Alth <OA...@de.ibm.com> wrote:

> But How can I read out those variables?

After calling setEnvironment("myenv") on a Property instance and calling
execute on the same instance, the environment variables are available
as properties, i.e. getProject().getProperty("myenv.PATH") will give you
the environment variable PATH if present.

If you really want to use Ant's API instead of Ant tasks, you'll find
that org.apache.tools.ant.taskdefs.Execute#getProcEnvironment is what
you really want, though.

Stefan