title: How can I use Java to run OS commands
body: <p>I'm making a program and that must call <em>Clafer</em> with <code>clafer -m=xml Case5.cfr</code>.</p>
  
  <p>So I use</p>
  
  <pre><code>ProcessBuilder pb = new ProcessBuilder("clafer -m=xml " + "Case5.cfr");
  pb.directory(new File("C:\\Users\\unituser\\workspace\\com.unitbilisim.clafer2Ecore\\src\\model\\"));
  Process P = pb.start();
  </code></pre>
  
  <p>but always get the following error:</p>
  
  <pre><code>Exception in thread "main" java.io.IOException: Cannot run program "clafer -m=xml Case5.cfr" (in directory "C:\Users\unituser\workspace\com.unitbilisim.clafer2Ecore\src\model"): CreateProcess error=2, The system cannot find the file specified
      at java.lang.ProcessBuilder.start(Unknown Source)
      at EmfCompare.emfCompareDeneme.main(emfCompareDeneme.java:54)
  Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
      at java.lang.ProcessImpl.create(Native Method)
      at java.lang.ProcessImpl.&lt;init&gt;(Unknown Source)
      at java.lang.ProcessImpl.start(Unknown Source)
      ... 2 more
  </code></pre>
  
  <p>I don't understand why. Can anyone help me?</p>