01: package hero.user;
02:
03: /**
04: *
05: * Bonita
06: * Copyright (C) 1999 Bull S.A.
07: * Bull 68 route de versailles 78434 Louveciennes Cedex France
08: * Further information: bonita@objectweb.org
09: *
10: * This library is free software; you can redistribute it and/or
11: * modify it under the terms of the GNU Lesser General Public
12: * License as published by the Free Software Foundation; either
13: * version 2.1 of the License, or any later version.
14: *
15: * This library is distributed in the hope that it will be useful,
16: * but WITHOUT ANY WARRANTY; without even the implied warranty of
17: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18: * Lesser General Public License for more details.
19: *
20: * You should have received a copy of the GNU Lesser General Public
21: * License along with this library; if not, write to the Free Software
22: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
23: * USA
24: *
25: *
26: --------------------------------------------------------------------------
27: * $Id: ReadEnv.java,v 1.4 2007/09/19 10:25:55 mvaldes Exp $
28: *
29: --------------------------------------------------------------------------
30: */
31:
32: import java.io.*;
33: import java.util.*;
34: import java.util.Properties;
35:
36: public class ReadEnv {
37: public static Properties getEnvVars() throws Exception {
38: Process p = null;
39: Properties envVars = new Properties();
40: Runtime r = Runtime.getRuntime();
41: String OS = System.getProperty("os.name").toLowerCase();
42: if (OS.indexOf("windows 9") > -1) {
43: p = r.exec("command.com /c set");
44: } else if ((OS.indexOf("nt") > -1)
45: || (OS.indexOf("windows 200") > -1)
46: || (OS.indexOf("windows vista") > -1)
47: || (OS.indexOf("windows xp") > -1)) {
48: p = r.exec("cmd.exe /c set");
49: } else {
50: p = r.exec("env");
51: }
52: BufferedReader br = new BufferedReader(new InputStreamReader(p
53: .getInputStream()));
54: String line;
55: while ((line = br.readLine()) != null) {
56: int idx = line.indexOf('=');
57: if (idx != -1) {
58: String key = line.substring(0, idx);
59: String value = line.substring(idx + 1);
60: envVars.setProperty(key, value);
61: }
62: }
63: return envVars;
64: }
65:
66: public void ReadEnv() {
67: }
68:
69: public String getVariable(String name) throws Exception {
70: Properties p = ReadEnv.getEnvVars();
71: String prop = p.getProperty(name);
72: if (prop == null)
73: prop = System.getProperty(name);
74: return (prop);
75: }
76: }
|