问题
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