• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get environment variable in linux  RSS feed

 
Venkatesh Rajendran
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to get environment variable in linux, I tried using System.getProperty() but it is returning null to me. can any one help me to solve the problem.
Thanks in advance.
Venkat
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can't get the OS environment directly with Java. You'll need to use Runtime.exec() and open the InputStream on the Process and then parse the results. Of course, doing it like that makes the application dependant on a particular OS.
 
Layne Lund
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are writing OS-dependent code like this, you should look at using another language, like C or C++. Java is meant to be system independent, so you want to avoid writing code that is not.
 
S. Ganapathy
Ranch Hand
Posts: 194
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find relavent information at java API's System.getenv() method. This is deprecated, but the alternatives might be given there.
 
Venkatesh Rajendran
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your information.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!