title: Executing cmd.exe commands from Java
body: <p>I'm trying to read a file from the user, in which each line is a <code>cmd.exe</code> command, and run it (it's okay to assume the commands are legal), but when I give a command like <code>echo hi</code>, I get runtime exception error:</p>
  
  <blockquote>
    <p>Exception in thread "main" java.io.IOException: Cannot run program "echo": CreateProcess error=2, The system cannot find the file specified</p>
  </blockquote>
  
  <p>I'm trying to run the commands like this:</p>
  
  <pre><code>Runtime.getRuntime().exec(command);
  </code></pre>
  
  <p>where <code>command = "echo hi"</code>. This does work for commands like <code>regedit</code> though, so it seems the runtime I'm getting is like the "run" window and not cmd. Is there a way to run these commands?</p>