• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing system environnement cariables  RSS feed

 
godbillot samuel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I'm try to access to some system environnement variable, like $TERM,$PATH, $LD_LIBRARY_PATH or user define variables. How can I do that ?
I can do it with something like:
Runtime.getRuntime().exec("echo $PATH")
but it's not very efficient, and not very clean.
Thx.
 
George Brown
Ranch Hand
Posts: 919
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the Sun JDK 1.2 API docs, giving an alternative to the deprecated System.getenv() method:
-- begin Sun stuff --
The preferred way to extract system-dependent information is the system properties of the java.lang.System.getProperty methods and the corresponding getTypeName methods of the Boolean, Integer, and Long primitive types. For example:
<pre>
String classPath = System.getProperty("java.class.path",".");
if (Boolean.getBoolean("myapp.exper.mode"))
enableExpertCommands();
</pre>
-- end Sun stuff --
If that doesn't work for you, there's always the JNDI... or you could store your values in a flatfile and read that into your java program.
I hope that helps.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!