Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IllegalArgumentException : Executable name has embedded quote, split the arguments

I'm getting an error :

IllegalArgumentException : Executable name has embedded quote, 
split the arguments 

While running the

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

I'm using Windows7 and Java7 machine .

Same line of code is working fine for other environments .

Suggest me some way .

like image 623
Gaurav Singh Avatar asked Jun 03 '13 05:06

Gaurav Singh


2 Answers

You have to put your parameters in a String array:

    String a = quote(exeFullPath);        
    String b = paramB;
    String[] cmd = new String[]{a,b};
    Process myExec = Runtime.getRuntime().exec(cmd, null, parentFolder);
like image 130
Alex Byrth Avatar answered Oct 21 '22 02:10

Alex Byrth


This happens because of a change in Java 7 update 21/Java 6 update 45.

The solution to your problem is to refactor your code to use java.lang.ProcessBuilder instead. For instance:

ProcessBuilder pb = new ProcessBuilder("command", "argument1", "argument2");
Map<String, String> env = pb.environment();
env.put("var1", "value1");
Process p = pb.start();
like image 30
Aleksander Blomskøld Avatar answered Oct 21 '22 01:10

Aleksander Blomskøld