问题描述
我正在尝试拦截使用Tess4J
时显示在屏幕上的红色Empty page!!
消息.我编写了一个简短的拦截器类,该类重写了print
和println
并替换了stdout
和stderr
来检查以下字符串:
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);
}
}
我测试了该类:它可以工作并且禁止我写到stdout
和stderr
的任何Empty page!!
.我没有成功从Tess4J
捕获到Empty page!!
消息,尽管该消息以红色打印到控制台.我的问题:如何截获并禁止显示此消息?
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?
谢谢.
推荐答案
您可能想模仿Tesseract的quiet
命令行选项,该选项具有debug_file /dev/null
.
You may want to emulate Tesseract's quiet
command-line option, which has debug_file /dev/null
.
api.setVariable("debug_file", "/dev/null");
或
instance.setTessVariable("debug_file", "/dev/null");
这篇关于截获来自Tess4J的控制台输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!