import java.util.Date;
import java.util.Enumeration;
import java.util.Hashtable;
+import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.Vector;
/** the executable to use with the script */
private String cgiExecutable = "perl";
-
+
+ /** additional arguments for the executable */
+ private List<String> cgiExecutableArgs = null;
+
/** the encoding to use for parameters */
private String parameterEncoding =
System.getProperty("file.encoding", "UTF-8");
cgiExecutable = getServletConfig().getInitParameter("executable");
}
+ if (getServletConfig().getInitParameter("executable-arg-1") != null) {
+ List<String> args = new ArrayList<String>();
+ for (int i = 1;; i++) {
+ String arg = getServletConfig().getInitParameter(
+ "executable-arg-" + i);
+ if (arg == null) {
+ break;
+ }
+ args.add(arg);
+ }
+ cgiExecutableArgs = args;
+ }
+
if (getServletConfig().getInitParameter("parameterEncoding") != null) {
parameterEncoding = getServletConfig().getInitParameter("parameterEncoding");
}
Process proc = null;
int bufRead = -1;
- String[] cmdAndArgs = new String[params.size() + 2];
-
- cmdAndArgs[0] = cgiExecutable;
-
- cmdAndArgs[1] = command;
-
- //create query arguments
- for (int i=0; i < params.size(); i++) {
- cmdAndArgs[i + 2] = params.get(i);
+ List<String> cmdAndArgs = new ArrayList<String>();
+ if (cgiExecutable.length() != 0) {
+ cmdAndArgs.add(cgiExecutable);
+ }
+ if (cgiExecutableArgs != null) {
+ cmdAndArgs.addAll(cgiExecutableArgs);
}
+ cmdAndArgs.add(command);
+ cmdAndArgs.addAll(params);
try {
rt = Runtime.getRuntime();
- proc = rt.exec(cmdAndArgs, hashToStringArray(env), wd);
+ proc = rt.exec(
+ cmdAndArgs.toArray(new String[cmdAndArgs.size()]),
+ hashToStringArray(env), wd);
String sContentLength = env.get("CONTENT_LENGTH");
<li><strong>debug</strong> - Debugging detail level for messages logged
by this servlet. Default 0.</li>
<li><strong>executable</strong> - The of the executable to be used to
-run the script. Default is <code>perl</code>.</li>
+run the script. You may explicitly set this parameter to be an empty string
+if your script is itself executable (e.g. an exe file). Default is
+<code>perl</code>.</li>
+<li><strong>executable-arg-1</strong>, <strong>executable-arg-2</strong>,
+and so on - additional arguments for the executable. These precede the
+CGI script name. By default there are no additional arguments.</li>
<li><strong>parameterEncoding</strong> - Name of the parameter encoding
-to be used with the GCI servlet. Default is
+to be used with the CGI servlet. Default is
<code>System.getProperty("file.encoding","UTF-8")</code>.</li>
<li><strong>passShellEnvironment</strong> - Should the shell environment
variables (if any) be passed to the CGI script? Default is