IllegalArgumentException:可执行文件名已嵌入引号,拆分参数

Gau*_*ngh 11 java exception illegalargumentexception

我收到一个错误:

IllegalArgumentException : Executable name has embedded quote, 
split the arguments 
Run Code Online (Sandbox Code Playgroud)

在运行时

Runtime.getRuntime().exec(cmd, envTokens, file1);
Run Code Online (Sandbox Code Playgroud)

我正在使用Windows7和Java7机器.

相同的代码行适用于其他环境.

建议我一些方法.

Ale*_*øld 15

这是因为Java 7更新21/Java 6更新45的更改.

您的问题的解决方案是重构代码以使用java.lang.ProcessBuilder.例如:

ProcessBuilder pb = new ProcessBuilder("command", "argument1", "argument2");
Map<String, String> env = pb.environment();
env.put("var1", "value1");
Process p = pb.start();
Run Code Online (Sandbox Code Playgroud)

  • 请注意,在Java 6 update 45中实现了相同的更改.http://www.oracle.com/technetwork/java/javase/6u45-relnotes-1932876.html (3认同)