Intercepting console output which originated from Tess4J

1.1k views Asked by At

I am trying to intercept the red Empty page!! message that gets printed to my screen when using Tess4J. I wrote a short interceptor class that overrides print and println and replaced stdout and stderr to check for this string:

private static class Interceptor extends PrintStream {
    public Interceptor(OutputStream out) {
        super(out, true);
    }
    @Override
    public void print(String s) {
        if ( !s.contains("Empty page!!") )
            super.print(s);
    }
    @Override
    public void println(String s) {
        if ( !s.contains("Empty page!!") )
            super.println(s);
    }
}

I tested the class: It works and suppresses any Empty page!! that I write to stdout and stderr. I do not succeed in catching the Empty page!! message from Tess4J that gets printed to my console in red though. My question: How can I intercept and suppress this message?

Thanks a bunch.

Screenshot Eclipse

1

There are 1 answers

6
nguyenq On BEST ANSWER

You may want to emulate Tesseract's quiet command-line option, which has debug_file /dev/null.

api.setVariable("debug_file", "/dev/null");

or

instance.setTessVariable("debug_file", "/dev/null");