Java – illegalargumentexception: the name of the executable file has embedded references and split parameters

I received an error:

IllegalArgumentException : Executable name has embedded quote,split the arguments

Runtime

Runtime.getRuntime().exec(cmd,envTokens,file1);

I am using Windows 7 and Java 7 machines

The same lines of code apply to other environments

Give me some advice

Solution

This is due to the change of Java 7 update 21 / Java 6 update 45

The solution to your problem is to refactor your code to use Java lang.ProcessBuilder. For example:

ProcessBuilder pb = new ProcessBuilder("command","argument1","argument2");
Map<String,String> env = pb.environment();
env.put("var1","value1");
Process p = pb.start();
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>