title: Java ProcessBuilder ignores Whitespaces
body: <p>I try to start a program via the Windows command shell out of Java and experience errors I cannot solve myself. I use a ProcessBuilder to pass the arguments to the command shell.</p>
  
  <p>Snippet:</p>
  
  <pre><code>try{
          List&lt;String&gt; list = new ArrayList&lt;String&gt;();
          list.add("cmd.exe");
          list.add("/c");
          list.add("C:\\Program Files (x86)\\TightVNC\\tvnserver.exe -controlservice -connect 172.20.242.187");
          ProcessBuilder builder = new ProcessBuilder(list);
          System.out.println(builder.command());
          builder.redirectErrorStream(true);
          Process p = builder.start();
          BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
          String line;
          while(true){
              line = r.readLine();
              if(line == null) { break; }
              System.out.println(line);
          }
  } catch {...}
  </code></pre>
  
  <p>My problem is that the whitespaces in the path to the program are ignored.
  Console output:</p>
  
  <blockquote>
    <p>[cmd.exe, /c, C:\Program Files (x86)\TightVNC\tvnserver.exe -controlservice -connect 172.20.242.187]
    Der Befehl "C:\Program" ist entweder falsch geschrieben oder
    konnte nicht gefunden werden.</p>
  </blockquote>
  
  <p>(C:\Program cannot be found).</p>
  
  <p>On the web i found similar problems even on StackOverflow and other websites did it exactly as I did, see an example at <a href="https://stackoverflow.com/questions/15464111/run-cmd-commands-through-java">Run cmd commands through java</a>
  with the difference I passed the arguments as a list mentioned in <a href="http://www.tutorialspoint.com/java/lang/processbuilder_command_list.htm" rel="nofollow noreferrer">http://www.tutorialspoint.com/java/lang/processbuilder_command_list.htm</a></p>
  
  <p>So I do not understand why my command is not working. I appreciate any help</p>
  
  <p><strong>Edit</strong> I have to add the path dynamically so I cannot pass the arguments when creating the ProcessBuilder object.</p>