Open cgoeller opened 6 months ago
It seems as if the bug exists in the apache-commons-exec library (tested with version 1.4.0)
This example app produces the same error message:
package org.example;
import java.io.IOException;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
public class App {
public static void main(String[] args) {
CommandLine commandLine = new CommandLine("C:\\Windows\\system32\\cmd.exe");
commandLine.addArgument("/c");
commandLine.addArgument("C:\\Program Files\\nodejs\\npx.cmd");
commandLine.addArgument("--node-options='--openssl-legacy-provider --max_old_space_size=4096'");
DefaultExecutor executor = DefaultExecutor.builder().get();
try {
int exitValue = executor.execute(commandLine);
System.out.println(exitValue);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
The call to org.apache.commons.exec.util.StringUtils#quoteArgument removes the last single quote from the argument, which seems incorrect.
Found some related issues
https://issues.apache.org/jira/browse/EXEC-36 https://issues.apache.org/jira/browse/EXEC-82 https://issues.apache.org/jira/browse/EXEC-83
Plugin Version 3.2.0 Maven: 3.9.6 Platform: Windows 10
The example contains three executions of which one is failing.
A windows .cmd script is executed which is located in a folder that contains spaces in its name. If the argument to that command contains quotes (single or double quotes) the execution fails.
Without arguments or with plain arguments it works as expected. A .cmd script in a folder without spaces works in all cases.
exec-example.zip