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]);
}
}

2 thoughts on “How to read environment variables

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

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