Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Getting Unix user environment Variables at Runtime

843798Dec 11 2002 — edited Jan 13 2003
Anyone have an idea as to how to get USER (not SYSTEM) Environment variables (Unix) at Runtime? I have toyed with the idea of using:

String command = "/usr/java/getENV.bat";
String myDesiredEnvironmentKey = "CUSTOM_TOP";
Process p = Runtime.getRuntime().exec(command);

BufferedReader instream = new BufferedReader(new InputStreamReader(p.getInputStream());

Hashtable hashProperties = new Hashtable();
while (instream.ready()) {
String somedata = instream.readLine();
int indexOfEqual = somedata.indexOf("=");
hashProperties.put(somedata.substring(0,indexOfEqual), somedata.substring(indexOfEqual+1));
}
String myDesiredEnvironmentVariable = hashProperties.get(myDesiredEnvironmentKey);

Haven't tried this yet but I would like to know if anyone has any ideas better than above?
Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 10 2003
Added on Dec 11 2002
6 comments
560 views