title: How to run the command 'pdflatex' in Java on Mac
body: <p>I've tried searching for the answer but none are working for me.</p>
  
  <p>I'm trying to run pdflatex in terminal from my java application on my Mac.</p>
  
  <p>In Terminal if i type:</p>
  
  <pre><code>open -a FireFox http://www.yahoo.co.uk
  </code></pre>
  
  <p>it opens yahoo.co.uk in my FireFox browser </p>
  
  <p>or</p>
  
  <pre><code>pdflatex x.tex
  </code></pre>
  
  <p>it processes the file</p>
  
  <p>In my Java code I type:</p>
  
  <pre><code>open -a FireFox http://www.yahoo.co.uk'
  </code></pre>
  
  <p>it opens yahoo.co.uk in my FireFox browser</p>
  
  <p>or</p>
  
  <pre><code>pdflatex x.tex
  </code></pre>
  
  <p>I get an error.</p>
  
  <p>Here's the Code:</p>
  
  <pre><code>public static void main(String args[]) {
  
      String s = null;
  
      try {
  
          Process p = Runtime.getRuntime().exec("pdflatex x.tex");
  
           BufferedReader stdInput = new BufferedReader(new
           InputStreamReader(p.getInputStream()));
  
           BufferedReader stdError = new BufferedReader(new
           InputStreamReader(p.getErrorStream()));
  
           // read the output from the command
           System.out.println("Here is the standard output of the command:\n");
           while ((s = stdInput.readLine()) != null) {
           System.out.println(s);
           }
  
           // read any errors from the attempted command
           System.out.println("Here is the standard error of the command (if any):\n");
           while ((s = stdError.readLine()) != null) {
           System.out.println(s);
           }
  
           System.exit(0);
      } catch (Exception e) {
          System.out.println("exception happened - here's what I know: ");
          e.printStackTrace();
          System.exit(-1);
      }
  }
  </code></pre>
  
  <p>Here's the error:</p>
  
  <blockquote>
    <p>exception happened - here's what I know: <br>
    java.io.IOException: Cannot run program "pdflatex": error=2, No such file or directory at <br>
    java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at <br>
    java.lang.Runtime.exec(Runtime.java:593) at <br>
    java.lang.Runtime.exec(Runtime.java:431) at <br>
    java.lang.Runtime.exec(Runtime.java:328) at <br>
    test.JavaRunCommand.main(JavaRunCommand.java:28) <br>
    Caused by: java.io.IOException: error=2, No such file or directory at  <br>
    java.lang.UNIXProcess.forkAndExec(Native Method) at <br>
    java.lang.UNIXProcess.(UNIXProcess.java:53) at <br>
    java.lang.ProcessImpl.start(ProcessImpl.java:91) at <br>
    java.lang.ProcessBuilder.start(ProcessBuilder.java:453)   ... 4 more <br></p>
  </blockquote>
  
  <p>I have tried JProc as it was a solution from another post, but it still has a similar error:</p>
  
  <blockquote>
    <p>Exception in thread "main" org.buildobjects.process.StartupException: <br>
    Could not startup process 'pdflatex x.tex '. <br>
    at org.buildobjects.process.Proc.(Proc.java:46) at <br>
    org.buildobjects.process.ProcBuilder.run(ProcBuilder.java:111) at <br>
    test.JavaRunCommand.main(JavaRunCommand.java:20)  <br>
    Caused by: java.io.IOException: <br>
    Cannot run program "pdflatex x.tex": error=2, No such file or directory at <br>
    java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at <br>
    java.lang.Runtime.exec(Runtime.java:593) at  <br>
    org.buildobjects.process.Proc.(Proc.java:43)    ... 2 more <br>
    Caused by: java.io.IOException: error=2, No such file or directory at <br>
    java.lang.UNIXProcess.forkAndExec(Native Method) at <br>
    java.lang.UNIXProcess.(UNIXProcess.java:53) at <br>
    java.lang.ProcessImpl.start(ProcessImpl.java:91) at <br>
    java.lang.ProcessBuilder.start(ProcessBuilder.java:453)   ... 4 more <br></p>
  </blockquote>