Monday, April 22, 2013

IllegalArgumentException - Executable name has embedded quote, split the arguments

The way your Java program deals with external command invocations can be Runtime.exec, java.lang.ProcessBuilder or calling a web server wrapper that avoids huge memory leaking (JVM-Fork() problem) as I have posted before.

If you are using Runtime.exec without arrays for parameters then most likely you will face an "IllegalArgumentException" starting with version 1.7.0_21 in Windows platforms. The message states "Executable name has embedded quote, split the arguments". The solution as explained by Oracle is to use an array if you stick to Runtime.exec or migrate to java.lang.ProcessBuilder. Please refer to for details.

I ignore if java7 has already corrected for good the momentary overcommit of swap space as a result of using fork() but we have found using the wrapper mentioned above has done the trick so far for us but for sure using a wrapper is not always an option.


Anonymous said...

Thank you, you're a life saver.

It sucks that I had to re-write some of my code due to a Java update, but at least the solution was clear.

Thanks again,

Unknown said...

"Exception in thread "Thread-4" java.lang.IllegalArgumentException: Executable name has embedded quote, split the arguments"
Code as below

public static void restartApplication(Runnable runBeforeRestart) throws IOException {
try {
// java binary
String java = System.getProperty("java.home") + "/bin/java";
// vm arguments


List vmArguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
StringBuffer vmArgsOneLine = new StringBuffer();
for (String arg : vmArguments) {
// if it's the agent argument : we ignore it otherwise the
// address of the old application and the new one will be in conflict
if (!arg.contains("-agentlib")) {
vmArgsOneLine.append(" ");
// init the command to execute, add the vm args
final StringBuffer cmd = new StringBuffer("\"" + java + "\" " + vmArgsOneLine);

// program main and program arguments
String[] mainCommand = System.getProperty("").split(" ");
//String[] mainCommand = System.getProperty(SUN_JAVA_COMMAND).split(" ");
// program main is a jar
if (mainCommand[0].endsWith(".jar")) {
// if it's a jar, add -jar mainJar
cmd.append("-jar " + new File(mainCommand[0]).getPath());
} else {
// else it's a .class, add the classpath and mainClass
cmd.append("-cp \"" + System.getProperty("java.class.path") + "\" " + mainCommand[0]);
// finally add program arguments
for (int i = 1; i < mainCommand.length; i++) {
cmd.append(" ");
//ProcessBuilder svnProcessBuilder = new ProcessBuilder(cmd.toString());
// execute the command in a shutdown hook, to be sure that all the
// resources have been disposed before restarting the application
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
try {

System.out.println("********** "+cmd.toString());

// byte bytes[] = cmd.toString().getBytes();


} catch (IOException e) {
// execute some custom code before restarting
if (runBeforeRestart!= null) {;
// exit
} catch (Exception e) {
// something went wrong
//throw new IOException("Error while trying to restart the application", e);
System.out.println("ERROR "+e);


pls tell solutions
thanx in advance

Nestor Urquiza said...

@shivling as explained in use a variant of Runtime.exec that allows the command and arguments to be specified in an array. What you are doing is concatenating in a string the whole command line.

The preferred method though is to use java.lang.ProcessBuilder in case you are in jdk5 and above.