title: How to start a process from Java with arguments which contain double-quotes
body: <p>I need to start a second Java process from my Java program, and one of the arguments to the forked process need to contain literal double-quote characters (<code>"</code>). How do I do that in a portable way, i.e. so that it at least works on Linux and Windows?</p>
  
  <hr>
  
  <p>I tried to use a <code>ProcessBuilder</code> (which was introduced to overcome problems of the <code>Runtime</code> class, right?) with an array of strings as command line, but still there was a problem with the parameter containing the quote:</p>
  
  <pre><code>List&lt;String&gt; commandLine = new ArrayList&lt;String&gt;();
  commandLine.add(new File(System.getProperty("java.home") + "/bin/java").getAbsolutePath());
  commandLine.addAll(Arrays.asList("-jar", "plugins/org.eclipse.equinox.launcher_1.3.0.v20120522-1813.jar", "-application", "org.eclipse.equinox.p2.director", "-repository", "http://download.eclipse.org/releases/juno"));
  commandLine.add("-list");
  commandLine.add("Q:select(x | x.id == \"org.eclipse.sdk.ide\")");
  
  new ProcessBuilder().command(commandLine).directory(eclipseInstallationDir).start().waitFor();
  </code></pre>
  
  <p>The code above doesn't work (on Windows) because the <code>ProcessBuilder</code> (or something else) eats up the double quotes in the last argument: </p>
  
  <p>Instead of <code>Q:select(x | x.id == "org.eclipse.sdk.ide")</code>, the process receives the argument <code>Q:select(x | x.id == org.eclipse.sdk.ide)</code> and then fails.</p>
  
  <hr>
  
  <p>I figured out that I can make it work on Windows by adding a <code>\"</code> in the argument where I need a <code>"</code> i.e.</p>
  
  <pre><code>commandLine.add("Q:select(x | x.id == \"org.eclipse.sdk.ide\")".replace("\"", "\\\""));
  </code></pre>
  
  <p>but this breaks the invocation on Linux (as morgano confirmed). So I'm forced to detect the OS again. Is there really no simple, portable way to start a process in Java where the arguments are exactly the content of a string array?</p>