ryo
ryo

Reputation: 2167

Java When using Process#start(), IOException is thrown

I want to convert .dvi to .pdf, using dvipdfmx command on Java. But my code throws IOException. I use OS X.

The following is Main.java.

 public class Main {
     public static void main(String[] args) throws IOException, InterruptedException {
         ProcessBuilder pb = new ProcessBuilder();
         pb.command("dvipdfmx", "myreport.dvi");
         Process process = pb.start();
         process.waitFor();
     }  
}

Please tell me how to solve the problem.

The following is output of error.

    Exception in thread "main" java.io.IOException: Cannot run program "dvipdfmx": error=2, No such file or directory
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1042)
    at Main.main(Main.java:11)
Caused by: java.io.IOException: error=2, No such file or directory
    at java.lang.UNIXProcess.forkAndExec(Native Method)
    at java.lang.UNIXProcess.<init>(UNIXProcess.java:185)
    at java.lang.ProcessImpl.start(ProcessImpl.java:134)
    at java.lang.ProcessBuilder.start(ProcessBuilder.java:1023)
    ... 1 more

Upvotes: 0

Views: 1841

Answers (1)

mindex
mindex

Reputation: 1636

As @chrylis has said in his comment, you should pass the absolute path to the executable (not only to the arg):

pb.command("/path/to/your/dvipdfmx", "/path/to/your/myreport.dvi");

Upvotes: 1

Related Questions