private Properties getEnvironmentVariables ( ) throws Throwable { Properties environmentVariables = new Properties ( ) ; String operatingSystem = System . getProperty ( "os.name" ) . toLowerCase ( ) ; Runtime runtime = Runtime . getRuntime ( ) ; Process process = null ; if ( operatingSystem . startsWith ( "windows 95" ) || operatingSystem . startsWith ( "windows 98" ) || operatingSystem . startsWith ( "me" ) ) { process = runtime . exec ( "command.com /c set" ) ; } else if ( operatingSystem . startsWith ( "windows" ) ) { // Modern windows process = runtime . exec ( "cmd.exe /c set" ) ; } else { process = runtime . exec ( "env" ) ; } BufferedReader environmentStream = new BufferedReader ( new InputStreamReader ( process . getInputStream ( ) ) ) ; String inputLine = "" ; int idx = - 1 ; while ( ( inputLine = environmentStream . readLine ( ) ) != null ) { idx = inputLine . indexOf ( ' ' ) ; environmentVariables . setProperty ( inputLine . substring ( 0 , idx ) , inputLine . substring ( idx + 1 ) ) ; } return environmentVariables ; }
Utility method to load the environment variables .