• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

env varriables

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I need a java code that gives me the env varriaales .
Can any one help .

Thanks
Tirthankar
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is an advanced question?
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No, it's not. Off to JiG Intermediate.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Try this code piece.

import java.util.Enumeration;
public class Env {
public static void main(String[] args) {
Enumeration objEnmSys = System.getProperties().keys();
while (objEnmSys.hasMoreElements()){
String strProp = objEnmSys.nextElement().toString();
System.out.println(strProp+"\t:"+System.getProperties().getProperty(strProp));
}
}
}
[ May 21, 2005: Message edited by: Mani RMK ]
 
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unfortunately System.getenv() is deprecated and doesn't work at all.

The documentation recommends to use System.getProperty() , as states in the previous reply.
However, we need to clarify that these are not the same.... you need to manually translate "environment vars" into "java system properties". This is usually done at the command-line executing java.

Example:

Cumbersome as it might seem, it does a good job separating java from the native platform. This approach is used by various commercial products, including Tomcat.

In rare cases when you feel there's no way you can take this approach, you can alwasy use the *platrom dependent* alternative, using Runtime.exec:
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
sorry, %DSQUERY% is just a system variable. Replace it with %MyVar%.
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use:


Unfortunately System.getenv() is deprecated and doesn't work at all.


does work for me.
From the javadocs:

When passing information to a Java subprocess, system properties are generally preferred over environment variables.
(...)
Since:
1.5


Introduced in 1.5 and deprecated today?
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
getenv() was present in early versions of Java; then it was deprecated for a few years; then in Tiger, it was un-deprecated, and now there's a shiny new version that returns the whole environment, as Stefan demonstrates.

Sometimes the Javasoft folks give in to a little pressure.
 
Sol Mayer-Orn
Ranch Hand
Posts: 311
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry, wasn't aware of that (my company's still using 1.4).
Thanks.
 
reply
    Bookmark Topic Watch Topic
  • New Topic