title: I need to execute a command line program in a specific working directory from Java
body: <p>I need to execute a command line program with 2 arguments. However, it must execute in the working directory. i.e. "command arg1 arg2", not "c:\folder\subfolder\command arg1 arg2"</p>
  
  <p>From other questions here, I've gotten up to using Runtime.exec(cmdArray, null, workingDirectory); but I keep getting "CreateProcess error=2, The system cannot find the file specified". I've checked, and both the path and file exist, so I don't know what is going wrong. Here is the code I'm using.</p>
  
  <pre><code>String [] fileName = {"mp3wrap.exe", "Clear_10", "*.mp3"};
  String dirName = "E:\\Music\\New Folder\\zz Concatinate\\Clear_10";
  try {
      Runtime rt = Runtime.getRuntime();
      Process pr = rt.exec(fileName, null, new File(dirName));
      BufferedReader input = new BufferedReader(new InputStreamReader
          (pr.getInputStream()));
      String line = null;
      while ((line = input.readLine()) != null) {
          System.out.println(line);
      }//end while
      int exitVal = pr.waitFor();
      System.out.println("Exited with error code " + exitVal);
  }//end try
  catch (Exception e) {
      System.out.println(e.toString());
      e.printStackTrace();
  }//end catch`
  </code></pre>
  
  <p>I'm getting this error:</p>
  
  <p>java.io.IOException: Cannot run program "mp3wrap.exe" (in directory "E:\Music\New Folder\zz Concatinate\Clear_10"): CreateProcess error=2, The system cannot find the file specified</p>