title: Execute Windows commands from Java
body: <p>I try to use following command to execute a Windows command in a given directory.</p>
  
  <pre><code>try{
      String command = "cmd /c start cmd.exe";
      Process child = Runtime.getRuntime().exec(command);
      OutputStream out = child.getOutputStream();
  
      out.write("cd /d C:\\_private\\Files\\testfiles".getBytes());
      out.flush();
      out.write("for /f \"DELIMS=\" %x in ('dir /ad /b') do move \"%x*.*\" \"%x\\\"".getBytes());
      out.close();
  }catch(IOException e){
  }
  </code></pre>
  
  <p>It just open up a Command prompt in directory, where Java project is located.</p>