Author: ngn Date: Sat Feb 11 16:14:47 2006 New Revision: 377094 URL: http://svn.apache.org/viewcvs?rev=377094&view=rev Log: Replacing the CommandLine class with String[] to work more like the JDK classes. Note that for now this also removes the special handling of quotes. Get back to this later.
Removed: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/CommandLine.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/CommandLineArgument.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/CommandLineImpl.java jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/CommandLineTest.java Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Exec.java Sat Feb 11 16:14:47 2006 @@ -149,6 +149,7 @@ // try to find the executable File executableFile = new File(exec); if (executableFile.exists()) { + return executableFile.getAbsolutePath(); } @@ -200,22 +201,22 @@ * <li>this list is not exhaustive or limitative</li> * </ul> */ - public void execute(final CommandLine cl) throws IOException { + public void execute(final String[] cl) throws IOException { execute(cl, null, new LogOutputStream(1), new LogOutputStream(2)); } - public void execute(final CommandLine cl, final Map env) + public void execute(final String[] cl, final Map env) throws IOException { execute(cl, env, new LogOutputStream(1), new LogOutputStream(2)); } - public void execute(final CommandLine cl, final OutputStream out, + public void execute(final String[] cl, final OutputStream out, final OutputStream error) throws IOException { execute(cl, null, out, error); } - public void execute(final CommandLine cmdl, final Map env, + public void execute(final String[] cmdl, final Map env, final OutputStream out, final OutputStream error) throws IOException { File savedDir = dir; // possibly altered in prepareExec @@ -227,7 +228,8 @@ environment = env; } - cmdl.setExecutable(resolveExecutable(executable, false)); + cmdl[0] = resolveExecutable(cmdl[0], false); + checkConfiguration(cmdl); try { @@ -238,7 +240,7 @@ } } - public void execute(final CommandLine cmdl, final Map env, + public void execute(final String[] cmdl, final Map env, final InputStream in, final OutputStream out, final OutputStream error) throws IOException { File savedDir = dir; // possibly altered in prepareExec @@ -250,7 +252,7 @@ environment = env; } - cmdl.setExecutable(resolveExecutable(executable, false)); + cmdl[0] = resolveExecutable(cmdl[0], false); checkConfiguration(cmdl); try { @@ -267,9 +269,9 @@ * @throws ExecuteException * if there are missing required parameters */ - protected void checkConfiguration(final CommandLine cmdl) + protected void checkConfiguration(final String[] cmdl) throws IOException { - if (cmdl.getExecutable() == null) { + if (cmdl.length == 0) { throw new IOException("No executable specified"); } if (dir != null && !dir.exists()) { @@ -350,7 +352,7 @@ // redirector.complete(); if (Execute.isFailure(returnCode)) { - throw new ExecuteException(exe.getCommandline().getExecutable() + throw new ExecuteException(exe.getCommandline()[0] + " failed with return code", returnCode); } } else { @@ -368,7 +370,7 @@ * if the new process could not be started only if * failIfExecFails is set to true (the default) */ - protected void runExec(final Execute exe, final CommandLine cmdl) + protected void runExec(final Execute exe, final String[] cmdl) throws IOException { // show the command log.debug(cmdl.toString()); Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/Execute.java Sat Feb 11 16:14:47 2006 @@ -40,7 +40,7 @@ /** Invalid exit code. * */ public static final int INVALID = Integer.MAX_VALUE; - private CommandLine cmdl = null; + private String[] cmdl = null; private Map environment = null; @@ -132,7 +132,7 @@ * * @return the command line used to create a subprocess */ - public CommandLine getCommandline() { + public String[] getCommandline() { return cmdl; } @@ -142,7 +142,7 @@ * @param commandline * the command line of the subprocess to launch */ - public void setCommandline(final CommandLine commandline) { + public void setCommandline(final String[] commandline) { cmdl = commandline; } @@ -211,7 +211,7 @@ * @throws IOException * forwarded from the particular launcher used */ - public static Process launch(final CommandLine command, final Map env, final File dir) + public static Process launch(final String[] command, final Map env, final File dir) throws IOException { CommandLauncher launcher = vmLauncher; @@ -419,7 +419,7 @@ * @throws ExecuteException * if the command does not return 0. */ - public static void runCommand(final CommandLine cmdline) + public static void runCommand(final String[] cmdline) throws IOException { try { LOG.debug(cmdline); @@ -428,12 +428,12 @@ exe.setCommandline(cmdline); int retval = exe.execute(); if (isFailure(retval)) { - throw new ExecuteException(cmdline.getExecutable() + throw new ExecuteException(cmdline[0] + " failed with return code", retval); } } catch (java.io.IOException exc) { throw new IOException("Could not launch " - + cmdline.getExecutable() + ": " + exc); + + cmdline[0] + ": " + exc); } } Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/ExecuteWatchdog.java Sat Feb 11 16:14:47 2006 @@ -65,15 +65,6 @@ } /** - * @see #ExecuteWatchdog(long) - * @deprecated Use constructor with a long type instead. (1.4.x - * compatibility) - */ - public ExecuteWatchdog(final int timeout) { - this((long) timeout); - } - - /** * Watches the given process and terminates it, if it runs for too long. All * information from the previous run are reset. * Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/DefaultProcessingEnvironment.java Sat Feb 11 16:14:47 2006 @@ -27,8 +27,6 @@ import java.util.HashMap; import java.util.Map; -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.CommandLineImpl; import org.apache.commons.exec.Execute; import org.apache.commons.exec.OS; import org.apache.commons.exec.PumpStreamHandler; @@ -116,37 +114,39 @@ return new BufferedReader(new StringReader(toString(out))); } - protected CommandLine getProcEnvCommand() { - CommandLine commandLine = new CommandLineImpl(); + protected String[] getProcEnvCommand() { + String[] commandLine; if (OS.isFamilyOS2()) { // OS/2 - use same mechanism as Windows 2000 - commandLine.setExecutable("cmd"); - commandLine.addArguments(new String[] {"/c", "set"}); + commandLine = new String[]{"cmd", "/c", "set"}; } else if (OS.isFamilyWindows()) { // Determine if we're running under XP/2000/NT or 98/95 + commandLine = new String[3]; if (OS.isFamilyWin9x()) { - commandLine.setExecutable("command.com"); + commandLine[0] = "command.com"; // Windows 98/95 } else { - commandLine.setExecutable("cmd"); + commandLine[0] = "cmd"; // Windows XP/2000/NT/2003 } - commandLine.addArguments(new String[] {"/c", "set"}); + commandLine[1] = "/c"; + commandLine[2] = "set"; } else if (OS.isFamilyZOS() || OS.isFamilyUnix()) { // On most systems one could use: /bin/sh -c env // Some systems have /bin/env, others /usr/bin/env, just try + commandLine = new String[1]; if (new File("/bin/env").canRead()) { - commandLine.setExecutable("/bin/env"); + commandLine[0] = "/bin/env"; } else if (new File("/usr/bin/env").canRead()) { - commandLine.setExecutable("/usr/bin/env"); + commandLine[0] = "/usr/bin/env"; } else { // rely on PATH - commandLine.setExecutable("env"); + commandLine[0] = "env"; } } else if (OS.isFamilyNetware() || OS.isFamilyOS400()) { // rely on PATH - commandLine.setExecutable("env"); + commandLine = new String[]{"env"}; } else { // MAC OS 9 and previous // TODO: I have no idea how to get it, someone must fix it Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/environment/OpenVmsProcessingEnvironment.java Sat Feb 11 16:14:47 2006 @@ -23,9 +23,6 @@ import java.util.Iterator; import java.util.Map; -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.CommandLineImpl; - public class OpenVmsProcessingEnvironment extends DefaultProcessingEnvironment { public synchronized Map getProcEnvironment() throws IOException { @@ -41,11 +38,8 @@ return procEnvironment; } - protected CommandLine getProcEnvCommand() { - CommandLine commandLine = new CommandLineImpl(); - commandLine.setExecutable("show"); - commandLine.addArgument("logical"); - return commandLine; + protected String[] getProcEnvCommand() { + return new String[]{"show", "logical"}; } /** Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncher.java Sat Feb 11 16:14:47 2006 @@ -21,9 +21,6 @@ import java.io.IOException; import java.util.Map; -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.environment.EnvironmentUtil; - public interface CommandLauncher { /** @@ -37,7 +34,7 @@ * @throws IOException * if attempting to run a command in a specific directory */ - Process exec(final CommandLine cmd, final Map env) + Process exec(final String[] cmd, final Map env) throws IOException; /** @@ -55,6 +52,6 @@ * @throws IOException * if trying to change directory */ - Process exec(final CommandLine cmd, final Map env, + Process exec(final String[] cmd, final Map env, final File workingDir) throws IOException; } Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherImpl.java Sat Feb 11 16:14:47 2006 @@ -21,7 +21,6 @@ import java.io.IOException; import java.util.Map; -import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.environment.EnvironmentUtil; /** @@ -31,17 +30,17 @@ */ public abstract class CommandLauncherImpl implements CommandLauncher { - public Process exec(final CommandLine cmd, final Map env) + public Process exec(final String[] cmd, final Map env) throws IOException { String[] envVar = null; if(env != null) { envVar = EnvironmentUtil.toStrings(env); } - return Runtime.getRuntime().exec(cmd.getCommandline(), + return Runtime.getRuntime().exec(cmd, envVar); } - public abstract Process exec(final CommandLine cmd, final Map env, + public abstract Process exec(final String[] cmd, final Map env, final File workingDir) throws IOException; } Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/CommandLauncherProxy.java Sat Feb 11 16:14:47 2006 @@ -20,8 +20,6 @@ import java.io.IOException; import java.util.Map; -import org.apache.commons.exec.CommandLine; - /** * A command launcher that proxies another command launcher. Sub-classes * override exec(args, env, workdir) @@ -45,7 +43,7 @@ * @throws IOException * forwarded from the exec method of the command launcher */ - public Process exec(final CommandLine cmd, final Map env) + public Process exec(final String[] cmd, final Map env) throws IOException { return myLauncher.exec(cmd, env); } Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/Java13CommandLauncher.java Sat Feb 11 16:14:47 2006 @@ -21,7 +21,6 @@ import java.io.IOException; import java.util.Map; -import org.apache.commons.exec.CommandLine; import org.apache.commons.exec.environment.EnvironmentUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -49,7 +48,7 @@ * @throws IOException * probably forwarded from Runtime#exec */ - public Process exec(final CommandLine cmd, final Map env, + public Process exec(final String[] cmd, final Map env, final File workingDir) throws IOException { log.debug("Execute:Java13CommandLauncher: " + cmd); @@ -58,7 +57,7 @@ envVars = EnvironmentUtil.toStrings(env); } - return Runtime.getRuntime().exec(cmd.getCommandline(), + return Runtime.getRuntime().exec(cmd, envVars, workingDir); } } Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/OS2CommandLauncher.java Sat Feb 11 16:14:47 2006 @@ -21,9 +21,6 @@ import java.io.IOException; import java.util.Map; -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.CommandLineImpl; - /** * A command launcher for OS/2 that uses 'cmd.exe' when launching commands in * directories other than the current working directory. @@ -51,16 +48,20 @@ * @throws IOException * forwarded from the exec method of the command launcher */ - public Process exec(final CommandLine cmd, final Map env, + public Process exec(final String[] cmd, final Map env, final File workingDir) throws IOException { if (workingDir == null) { return exec(cmd, env); } - CommandLine newCmd = new CommandLineImpl(); - newCmd.setExecutable("cmd"); - newCmd.addArgument("/c"); - newCmd.addArguments(cmd.getCommandline()); + // TODO add code for switching to working dir + String[] newCmd = new String[cmd.length + 2]; + newCmd[0] = "cmd"; + newCmd[1] = "/c"; + + for (int i = 0; i < cmd.length; i++) { + newCmd[i + 2] = cmd[i]; + } return exec(newCmd, env); } Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java Sat Feb 11 16:14:47 2006 @@ -26,9 +26,6 @@ import java.util.Set; import java.util.Map.Entry; -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.CommandLineImpl; - /** * A command launcher for VMS that writes the command to a temporary DCL script * before launching commands. This is due to limitations of both the DCL @@ -39,10 +36,10 @@ /** * Launches the given command in a new process. */ - public Process exec(final CommandLine cmd, final Map env) + public Process exec(final String[] cmd, final Map env) throws IOException { - CommandLine vmsCmd = new CommandLineImpl(); - vmsCmd.setExecutable(createCommandFile(cmd, env).getPath()); + String[] vmsCmd = new String[1]; + vmsCmd[0] = createCommandFile(cmd, env).getPath(); return super.exec(vmsCmd, env); } @@ -53,10 +50,10 @@ * only works if <code>workingDir</code> is null or the logical * JAVA$FORK_SUPPORT_CHDIR needs to be set to TRUE. */ - public Process exec(final CommandLine cmd, final Map env, + public Process exec(final String[] cmd, final Map env, final File workingDir) throws IOException { - CommandLine vmsCmd = new CommandLineImpl(); - vmsCmd.setExecutable(createCommandFile(cmd, env).getPath()); + String[] vmsCmd = new String[1]; + vmsCmd[0] = createCommandFile(cmd, env).getPath(); return super.exec(vmsCmd, env, workingDir); } @@ -65,9 +62,9 @@ * Writes the command into a temporary DCL script and returns the * corresponding File object. The script will be deleted on exit. */ - private File createCommandFile(final CommandLine cmd, final Map env) + private File createCommandFile(final String[] cmd, final Map env) throws IOException { - File script = File.createTempFile("ANT", ".COM"); + File script = File.createTempFile("EXEC", ".COM"); script.deleteOnExit(); PrintWriter out = null; try { @@ -87,11 +84,15 @@ } } - out.print("$ " + cmd.getExecutable()); - String[] args = cmd.getArguments(); - for (int i = 0; i < args.length; i++) { - out.println(" -"); - out.print(args[i]); + if(cmd.length == 0) { + throw new IOException("Can not execute empty command"); + } else { + out.print("$ " + cmd[0]); + + for (int i = 1; i < cmd.length; i++) { + out.println(" -"); + out.print(cmd[i]); + } } } finally { if (out != null) { Modified: jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/main/java/org/apache/commons/exec/launcher/WinNTCommandLauncher.java Sat Feb 11 16:14:47 2006 @@ -21,9 +21,6 @@ import java.io.IOException; import java.util.Map; -import org.apache.commons.exec.CommandLine; -import org.apache.commons.exec.CommandLineImpl; - /** * A command launcher for Windows XP/2000/NT that uses 'cmd.exe' when launching * commands in directories other than the current working directory. @@ -46,7 +43,7 @@ * @throws IOException * forwarded from the exec method of the command launcher */ - public Process exec(final CommandLine cmd, final Map env, + public Process exec(final String[] cmd, final Map env, final File workingDir) throws IOException { if (workingDir == null) { return exec(cmd, env); @@ -54,10 +51,15 @@ // Use cmd.exe to change to the specified directory before running // the command - CommandLine newCmd = new CommandLineImpl(); - newCmd.setExecutable("cmd"); - newCmd.addArgument("/c"); - newCmd.addArguments(cmd.getCommandline()); + // TODO add code for switching to working dir + + String[] newCmd = new String[cmd.length + 2]; + newCmd[0] = "cmd"; + newCmd[1] = "/c"; + + for (int i = 0; i < cmd.length; i++) { + newCmd[i + 2] = cmd[i]; + } return exec(newCmd, env); } Modified: jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/ExecTest.java Sat Feb 11 16:14:47 2006 @@ -18,6 +18,7 @@ package org.apache.commons.exec; import java.io.ByteArrayOutputStream; +import java.io.File; import java.util.HashMap; import java.util.Map; @@ -36,8 +37,7 @@ public void testExecute() throws Exception { Exec exec = new Exec(); - CommandLine cl = new CommandLineImpl(); - cl.setExecutable(testScript); + String[] cl = new String[]{new File(testScript).getAbsolutePath()}; exec.execute(cl, baos, baos); @@ -47,9 +47,7 @@ public void testExecuteWithArg() throws Exception { Exec exec = new Exec(); - CommandLine cl = new CommandLineImpl(); - cl.setExecutable(testScript); - cl.addArgument("BAR"); + String[] cl = new String[]{testScript, "BAR"}; exec.execute(cl, baos, baos); assertEquals("FOO..BAR", baos.toString().trim()); @@ -59,8 +57,7 @@ Map env = new HashMap(); env.put("TEST_ENV_VAR", "XYZ"); - CommandLine cl = new CommandLineImpl(); - cl.setExecutable(testScript); + String[] cl = new String[]{testScript}; Exec exec = new Exec(); Modified: jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java URL: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java?rev=377094&r1=377093&r2=377094&view=diff ============================================================================== --- jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java (original) +++ jakarta/commons/sandbox/exec/trunk/src/test/java/org/apache/commons/exec/TestUtil.java Sat Feb 11 16:14:47 2006 @@ -17,6 +17,7 @@ package org.apache.commons.exec; +import java.io.File; import java.util.Arrays; import junit.framework.AssertionFailedError; @@ -28,13 +29,17 @@ } public static String resolveScriptForOS(String script) { + String scriptFileName; + if (OS.isFamilyWindows()) { - return script + ".bat"; + scriptFileName = script + ".bat"; } else if (OS.isFamilyUnix()) { - return script + ".sh"; + scriptFileName = script + ".sh"; } else { throw new AssertionFailedError("Test not supported for this OS"); } + + return new File(scriptFileName).getAbsolutePath(); } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]