Run Java app from Java with space in .jar file path
<p>I'm trying to run Java CUP (Java version for LEX/YACC parser) from within a Java application.</p>

<p>This is the code I have (I copied most of it from the internet):</p>

<pre><code>String command  = "java " +
                  "-jar " +
                  "\"g:My Documents\\Dropbox\\Final Project\\Code\\Mano CPU\\Inputs\\Parser\\java-cup-11a.jar\" " +
                  "-destdir " +
                  "\"g:\\My Documents\\Dropbox\\Final Project\\Code\\Mano CPU\\src\\Assembler\" " +
                  "\"G:\\My Documents\\Dropbox\\Final Project\\Code\\Mano CPU\\Inputs\\Assembler\\Assembler.cup\"";

Process p = Runtime.getRuntime().exec(command);
BufferedReader reader=new BufferedReader(new InputStreamReader(p.getInputStream()));
String line=reader.readLine();
while(line!=null)
{
    System.out.println(line);
    line=reader.readLine();
}
</code></pre>

<p>When I run this command in the command prompt of Win 7 (Without escaping the back-slashes and double-quoutes), it gets executed. If I comment out everything after "-jar", I get the java options (Which is expected, as the command is illegal), so I know it can run.</p>

<p>My guess is that passing a path with spaces is the problem. I tried using String[], but I get the same results. Escaping the spaces causes an error as well.</p>

<p>Does anybody have any idea as to how I can solve this?</p>

<p>Thanks.</p>
