By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,872 Members | 2,392 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,872 IT Pros & Developers. It's quick & easy.

How to read Enviroment variable in Java?

P: n/a
Hi,

I have a Java program that needs to access the value of variable
PATH (Set in Unix enviroment by setenv or DOS enviroment by PATH
statement). How do I access it in Java?

Thanks in advance,

Nikhil
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"Nikhil Barthwal" <nb**@iitk.ac.in> wrote in message
news:9d**************************@posting.google.c om...
Hi,

I have a Java program that needs to access the value of variable
PATH (Set in Unix enviroment by setenv or DOS enviroment by PATH
statement). How do I access it in Java?


You may execute (using method Runtime.exec()) the following command line
Windows 95/98/Me: command.com /c set
Windows NT/2000/XP: cmd /c set
Unix: env
and then parse output. It must have format like this:
<variable name>=<variable value>

By the way, Apache Ant uses this aproach. Look at:
org/apache/tools/ant/taskdefs/Execute.java
Jul 17 '05 #2

P: n/a
nb**@iitk.ac.in (Nikhil Barthwal) wrote in message news:<9d**************************@posting.google. com>...
Hi,

I have a Java program that needs to access the value of variable
PATH (Set in Unix enviroment by setenv or DOS enviroment by PATH
statement). How do I access it in Java?

Thanks in advance,

Nikhil


Older Java and the newest 1.5 have getenv() method in the java.lang.System class.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.