1 package hero.user; 2 3 31 32 import java.io.*; 33 import java.util.*; 34 35 public class ReadEnv { 36 public static Properties getEnvVars() throws Exception { 37 Process p = null; 38 Properties envVars = new Properties(); 39 Runtime r = Runtime.getRuntime(); 40 String OS = System.getProperty("os.name").toLowerCase(); 41 if (OS.indexOf("windows 9") > -1) { 42 p = r.exec( "command.com /c set" ); 43 } 44 else if ( (OS.indexOf("nt") > -1) 45 || (OS.indexOf("windows 2000") > -1 ) 46 || (OS.indexOf("windows xp") > -1) ) { 47 p = r.exec( "cmd.exe /c set" ); 48 } 49 else { 50 p = r.exec( "env" ); 51 } 52 BufferedReader br = new BufferedReader 53 ( new InputStreamReader( p.getInputStream() ) ); 54 String line; 55 while( (line = br.readLine()) != null ) { 56 int idx = line.indexOf( '=' ); 57 String key = line.substring( 0, idx ); 58 String value = line.substring( idx+1 ); 59 envVars.setProperty( key, value ); 60 } 61 return envVars; 62 } 63 64 public void ReadEnv(){} 65 66 public String getVariable(String name) throws Exception { 67 Properties p = ReadEnv.getEnvVars(); 68 return (p.getProperty(name)); 69 } 70 } 71 72 | Popular Tags |