KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hero > user > ReadEnv


1 package hero.user;
2
3 /**
4 *
5 * Bonita
6 * Copyright (C) 1999 Bull S.A.
7 * Bull 68 route de versailles 78434 Louveciennes Cedex France
8 * Further information: bonita@objectweb.org
9 *
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.1 2004/11/10 17:10:50 mvaldes Exp $
28 *
29 --------------------------------------------------------------------------
30 */

31
32 import java.io.*;
33 import java.util.*;
34
35 public class ReadEnv {
36  public static Properties getEnvVars() throws Exception JavaDoc {
37   Process JavaDoc p = null;
38   Properties envVars = new Properties();
39   Runtime JavaDoc r = Runtime.getRuntime();
40   String JavaDoc 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 JavaDoc line;
55   while( (line = br.readLine()) != null ) {
56    int idx = line.indexOf( '=' );
57    String JavaDoc key = line.substring( 0, idx );
58    String JavaDoc value = line.substring( idx+1 );
59    envVars.setProperty( key, value );
60    }
61   return envVars;
62   }
63
64   public void ReadEnv(){}
65  
66   public String JavaDoc getVariable(String JavaDoc name) throws Exception JavaDoc{
67      Properties p = ReadEnv.getEnvVars();
68      return (p.getProperty(name));
69   }
70 }
71  
72
Popular Tags