title: How to invoke a CMD file in JAVA correctly on windows?
body: <p>I have sample java code like below.</p>
  
  <pre><code>    String testEfdDirectoryPath="D:\\test";
      String efdExecutable = "test.cmd";
      File executableFile = new File(testEfdDirectoryPath, efdExecutable);
      ProcessBuilder pb=new ProcessBuilder();
      $$pb.command("cmd.exe","/C",executableFile.toString());$$
      pb.directory(new File(testEfdDirectoryPath));
      Process p=pb.start();
      int code=p.waitFor();
      System.out.print(code);
  </code></pre>
  
  <p>In test.cmd there is actually a call to another java application. Unless I change the $$ marked line to the following to redirect its output, the another java app cannot be launched.</p>
  
  <pre><code>    pb.command("cmd.exe","/C",executableFile.toString(),"&gt;output.txt");
  </code></pre>
  
  <p>Do you guys have any ideas? Thanks in advance. :) </p>