Intercepting console output which originated from Tess4J

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-11 23:44:31

问题


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.


回答1:


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");


来源:https://stackoverflow.com/questions/26894575/intercepting-console-output-which-originated-from-tess4j

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!