2 package org
.de
.metux
.util
;
4 import java
.io
.BufferedReader
;
5 import java
.io
.IOException
;
6 import java
.util
.Properties
;
7 import java
.io
.InputStreamReader
;
10 grabbed this code somewhere on the web
12 we need it since stupid folks @ sun tend to remove essential functions
13 from java-spec and other stupid folks on various vm projects had
16 this class is a really ugly hack!
17 imagine: we have to spawn another process just for retrieving
18 the env of this process.
19 against the wall w/ the dude who decided to remove System.getenv()
22 public class Environment
extends Properties
28 String os
= System
.getProperty("os.name").toLowerCase();
30 if (os
.indexOf("windows")!=-1)
31 cmd
= ((os
.indexOf("95")!=-1 ||
32 (os
.indexOf("98")!=-1) ||
33 (os
.indexOf("ME")!=-1)) ?
"command.com":"cmd")+" /Cset";
39 Process p
= Runtime
.getRuntime().exec(cmd
);
40 load(p
.getInputStream());
41 BufferedReader br
= new BufferedReader(new InputStreamReader(p
.getInputStream()));
42 for (String line
=""; (line
=br
.readLine())!=null;)
44 int pos
= line
.indexOf("=");
45 setProperty(line
.substring(0,pos
),line
.substring(pos
+1));
51 setProperty("__EXCEPTION", e
.toString());
55 static Environment env
;
57 public static String
getenv(String name
)
60 env
= new Environment();
61 return env
.getProperty(name
);
64 public static String
getenv(String name
, String def
)
66 String s
= getenv(name
);
72 public static boolean getenv_bool(String name
, boolean def
)
74 String val
= getenv(name
,null);
77 val
= val
.toLowerCase();
79 if (val
.equals("on")||val
.equals("yes")||val
.equals("true")||val
.equals("1"))
81 if (val
.equals("off")||val
.equals("no")||val
.equals("false")||val
.equals("0"))
84 throw new RuntimeException("getenv_bool(): could not decode \""+val
+"\"");