OCR: java.io.IOException: Cannot run program "cmd": error=2, No such file or directory

1,269 views
Skip to first unread message

Rakesh Kumar

unread,
Sep 21, 2018, 2:10:15 PM9/21/18
to tesseract-ocr



I have successfully installed tesseract in my MAC.
Now trying to read and write image text using below code and found error. I am missing some thing or doing some thing wrong. Can any one help me with Java code to achieve this?

Refer attachment or In this link you can see the project: 




Error:    
java.io.IOException: Cannot run program "cmd": error=2, No such file or          directory

 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
 at java.lang.Runtime.exec(Runtime.java:620)
 at java.lang.Runtime.exec(Runtime.java:485)
 at com.chillyfacts.com.my_main.main(my_main.java:13)
 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:247)
 at java.lang.ProcessImpl.start(ProcessImpl.java:134)
 at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
 ... 3 more


            import java.io.PrintWriter;
        public class my_main {
    public static void main(String[] args) {
String input_file="/usr/local/Cellar/tesseract/apps.png";
String output_file="/usr/local/Cellar/";
String tesseract_install_path="/usr/local/Cellar/tesseract/";
String[] command = { "cmd" };
    Process p;
try {
p = Runtime.getRuntime().exec(command);
        new Thread(new SyncPipe(p.getErrorStream(), System.err)).start();
                new Thread(new SyncPipe(p.getInputStream(), System.out)).start();
                PrintWriter stdin = new PrintWriter(p.getOutputStream());
                stdin.println("\""+tesseract_install_path+"\" \""+input_file+"\" \""+output_file+"\" -l eng");
            stdin.close();
                p.waitFor();
                System.out.println();
                System.out.println();
                System.out.println();
                System.out.println();
                System.out.println(Read_File.read_a_file(output_file+".txt"));
    } catch (Exception e) {
e.printStackTrace();
}
}
}
Java_imagetotext.zip

Quan Nguyen

unread,
Sep 22, 2018, 1:24:21 AM9/22/18
to tesseract-ocr
cmd is Windows' command line interpreter. Does MacOS have that?

Rakesh Kumar

unread,
Sep 22, 2018, 9:51:27 AM9/22/18
to tesseract-ocr
I am looking what works for MAC
Reply all
Reply to author
Forward
0 new messages