Getting Unix user environment Variables at Runtime
843798Dec 11 2002 — edited Jan 13 2003Anyone 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