How to read environment variables

By the talented team way:

 String os = System.getProperty("os.name").toLowerCase();
if (os.indexOf("win") >= 0) {
p = r.exec("cmd.exe /c set");
} else {
p = r.exec("env");
}
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null)
{
String[] inputs = line.split("=");
if ("DOCUMENTUM".equalsIgnoreCase(inputs[0])) {
retCode = inputs[1];
}
}
if (br != null) {
br.close();
}

I guess System.getenv was way too complex…

Oh, and they use the same method to read a properties file:

while ((record = dis.readLine()) != null)
{
recCount++;
if ((!record.startsWith("#")) && (!record.trim().equalsIgnoreCase("")))
{
String[] inputs = record.split("=");
params.put(inputs[0], inputs[1]);
}
}

4 thoughts on “How to read environment variables

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.