From e1b5e97d0adf1f221ba918e6f1204c9cb0e0c970 Mon Sep 17 00:00:00 2001 From: markt Date: Fri, 28 Mar 2008 21:18:25 +0000 Subject: [PATCH] Remove hack for getting env since JDK >= 1.5 provide a suitable method. Fixes issue with CGI, env and vista. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@642391 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/servlets/CGIServlet.java | 57 +---------------------- 1 file changed, 1 insertion(+), 56 deletions(-) diff --git a/java/org/apache/catalina/servlets/CGIServlet.java b/java/org/apache/catalina/servlets/CGIServlet.java index d7588d6cf..a69cf4eb7 100644 --- a/java/org/apache/catalina/servlets/CGIServlet.java +++ b/java/org/apache/catalina/servlets/CGIServlet.java @@ -304,13 +304,7 @@ public final class CGIServlet extends HttpServlet { Boolean.valueOf(getServletConfig().getInitParameter("passShellEnvironment")).booleanValue(); if (passShellEnvironment) { - try { - shellEnv.putAll(getShellEnvironment()); - } catch (IOException ioe) { - ServletException e = new ServletException( - "Unable to read shell environment variables", ioe); - throw e; - } + shellEnv.putAll(System.getenv()); } if (getServletConfig().getInitParameter("executable") != null) { @@ -637,55 +631,6 @@ public final class CGIServlet extends HttpServlet { System.out.println("$Header$"); } - /** - * Get all shell environment variables. Have to do it this rather ugly way - * as the API to obtain is not available in 1.4 and earlier APIs. - * - * See Read environment - * variables from an application for original source and article. - */ - private Hashtable getShellEnvironment() throws IOException { - Hashtable envVars = new Hashtable(); - Process p = null; - Runtime r = Runtime.getRuntime(); - String OS = System.getProperty("os.name").toLowerCase(); - boolean ignoreCase; - - if (OS.indexOf("windows 9") > -1) { - p = r.exec( "command.com /c set" ); - ignoreCase = true; - } else if ( (OS.indexOf("nt") > -1) - || (OS.indexOf("windows 20") > -1) - || (OS.indexOf("windows xp") > -1) ) { - // thanks to JuanFran for the xp fix! - p = r.exec( "cmd.exe /c set" ); - ignoreCase = true; - } else { - // our last hope, we assume Unix (thanks to H. Ware for the fix) - p = r.exec( "env" ); - ignoreCase = false; - } - - BufferedReader br = new BufferedReader - ( new InputStreamReader( p.getInputStream() ) ); - String line; - while( (line = br.readLine()) != null ) { - int idx = line.indexOf( '=' ); - String key = line.substring( 0, idx ); - String value = line.substring( idx+1 ); - if (ignoreCase) { - key = key.toUpperCase(); - } - envVars.put(key, value); - } - return envVars; - } - - - - - - /** * Encapsulates the CGI environment and rules to derive -- 2.11.0