1

I'm trying to run the following command

tesseract test10.png text -l nor

using Java's

Runtime.getRuntime().exec()

command.

It is working when using, the simple "cmd /c dir" command, but I can not figure out the correct syntax/way to use the command.

Please help!

jorgen
  • 1,217
  • 6
  • 22
  • 41
  • 1
    possible duplicate of [How to Execute Windows Commands Using Java - Change Network Settings](http://stackoverflow.com/questions/7112259/how-to-execute-windows-commands-using-java-change-network-settings) – Perception Oct 13 '11 at 14:09
  • 1
    Read [When Runtime.exec() won't](http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html) & implement **every** recommendation it offers. – Andrew Thompson Oct 13 '11 at 14:25
  • BTW - if you have a question, I suggest you ask it. – Andrew Thompson Oct 13 '11 at 14:25

3 Answers3

1

This works:

try {
        Runtime rt = Runtime.getRuntime();
        Process pr = rt.exec("C:\\Path_to_tesseract\\tesseract.exe D:\\image.png D:\\outputFile");

        BufferedReader input = new BufferedReader(new InputStreamReader(pr.getInputStream()));

        String line=null;

        while((line=input.readLine()) != null) {
            System.out.println(line);
        }

        int exitVal = pr.waitFor();
        System.out.println("Exited with error code "+exitVal);

    } catch(Exception e) {
        System.out.println(e.toString());
        e.printStackTrace();
    }
maxivis
  • 1,727
  • 3
  • 21
  • 35
1

do you use exec(String cmd) or exec(String[] cmd)?

sometimes I had problems with the first one, though I can't tell, what went wrong

if you exec "tesseract test10.png text -l nor" then try out "cmd /C \"tesseract test10.png text -l nor\"" (and the same as String[]) maybe some of these work

Hachi
  • 3,237
  • 1
  • 21
  • 29
0

Take a look at OCR.java file of VietOCR, which uses ProcessBuilder to invoke Tesseract executable.

nguyenq
  • 8,212
  • 1
  • 16
  • 16