commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeremias Rößler (JIRA) <>
Subject [jira] Created: (EXEC-54) Problem with argument containing spaces
Date Tue, 08 Feb 2011 08:13:57 GMT
Problem with argument containing spaces

                 Key: EXEC-54
             Project: Commons Exec
          Issue Type: Bug
    Affects Versions: 1.1
         Environment: Mac OsX 10.6.6, JVM 1.6.0
            Reporter: Jeremias Rößler

I am new to Commons Exec, so this could also be an error in usage, but... 

When I use the {{CommandLine}} class to add a argument that contains spaces, some quotes are
added and are then part of the argument that is given.

For example: When I call {{java "what version"}} I get {{java.lang.NoClassDefFoundError: what
version}}, and when I call {{java "\"what version\""}} (which contains escaped quotes, that
are part of the command line argument itself), I get {{java.lang.NoClassDefFoundError: "what

So the following test fails, because as you can see in the last line, Apache Exec is producing
the latter version where it should have produced the first version:

	public void testArgumentQuoting() throws Exception {
		String argument = "what version";
		DefaultExecutor executor = new DefaultExecutor();
		DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
		ByteArrayOutputStream out = new ByteArrayOutputStream();
		PumpStreamHandler streamHandler = new PumpStreamHandler(out, out);
		CommandLine cmdLine = new CommandLine("java");
		executor.execute(cmdLine, resultHandler);
		String resultPattern = "Exception in thread \"main\" java\\.lang\\.NoClassDefFoundError:
([\\w \"]+)";
		Pattern pattern = Pattern.compile(resultPattern);
		Matcher matcher = pattern.matcher(out.toString());
		// Note: Result should be <what version> and NOT <"what version">!

Note that the same test passes if the space is removed from the argument. Please also note,
that I am not trying to start an external Java process, but this is merely an example that
I assume will work on every developers machine.

This message is automatically generated by JIRA.
For more information on JIRA, see:


View raw message