title: Running echo command from Java
body: <p>I want to print the output of <code>echo %path%</code> from <code>Java</code> instead of <code>cmd</code>.</p>
  
  <p>I have the following code:</p>
  
  <pre><code>private void getPath() throws IOException {
      String getPath = "cmd.exe /C echo %path%";
      Runtime rt = Runtime.getRuntime();
      Process proc = rt.exec(getPath);
      BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
      String commandOutput = "";
      while (commandOutput != null) {
          commandOutput = reader.readLine();
          System.out.println(commandOutput);
      }
  }
  </code></pre>
  
  <p>If I run <code>echo %path%</code> from the <code>cmd</code> the output begins with:</p>
  
  <blockquote>
    <p>C:\Oracle\Ora11\bin;C:\Oracle\Ora10\bin;C:\Program Files\Common</p>
  </blockquote>
  
  <p>But the output of the <code>Java</code> program begins with:</p>
  
  <blockquote>
    <p>C:/Program Files/Java/jre7/bin/client;C:/Program
    Files/Java/jre7/bin;C:/Program Files/Java/jre7/lib/i386</p>
  </blockquote>
  
  <p>and only after this line, the rest of the output is similar.</p>
  
  <p>Why is this happening?</p>