title: How to open the command prompt and insert commands using Java?
body: <p>Is it possible to open the command prompt (and I guess any other terminal for other systems), and execute commands in the newly opened window? </p>
  
  <p>Currently what I have is this:</p>
  
  <pre><code>Runtime rt = Runtime.getRuntime();
  rt.exec(new String[]{"cmd.exe","/c","start"});
  </code></pre>
  
  <p>I've tried adding the next command after the "start", I've tried running another rt.exec containing my command, but I can't find a way to make it work. </p>
  
  <p>If it matters, I'm trying to run a command similar to this:</p>
  
  <pre><code>java -flag -flag -cp terminal-based-program.jar
  </code></pre>
  
  <p><strong>EDIT</strong> Unfortunately I have had some strange findings. I've been able to successfully launch the command prompt and pass a command using this:</p>
  
  <pre><code>rt.exec("cmd.exe /c start command");
  </code></pre>
  
  <p>However, it only seems to work with one command. Because, if I try to use the command separator like this, "cmd.exe /c start command&amp;command2", the second command is passed through the background (the way it would if I just used rt.exec("command2");).  Now the problem here is, I realized that I need to change the directory the command prompt is running in, because if I just use the full path to the jar file, the jar file incorrectly reads the data from the command prompt's active directory, not the jar's directory which contains its resources. </p>