简体   繁体   English

为什么不打印到Eclipse中的控制台?

[英]Why isn't this printing to the console in Eclipse?

Given this code, I am baffled as to why it doesn't print to the console.... 有了这段代码,我很困惑为什么它无法打印到控制台。

    engine.compileTemplate(new PrintWriter(System.err));
    System.err.flush();

I see nothing on the console. 我在控制台上看不到任何东西。 Same problem with System.out too. System.out也有同样的问题。 And yes I verified that the code works by printing to a file successfully. 是的,我通过成功打印到文件来验证代码是否有效。

Try using the constructor with autoflush . 尝试将构造函数与autoflush一起使用 You are flushing System.err, not the PrintWriter. 您正在刷新System.err,而不是PrintWriter。

In what context is this code executed? 在什么情况下执行此代码? Really need more info to determine what's going on. 确实需要更多信息来确定正在发生的事情。

Is your code running in a plugin that you are debugging? 您的代码是否在要调试的插件中运行? If so, then with "print to the console" - do you mean the console of the same Eclipse instance as your plugin? 如果是这样,则使用“打印到控制台”-您是指与插件相同的Eclipse实例的控制台吗?

For that you would need to do something like: 为此,您需要执行以下操作:

MessageConsole console = new MessageConsole("My Console", null);
console.activate();
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });
MessageConsoleStream consoleStream = console.newMessageStream();
consoleStream.println("Hello, world!");

Otherwise, it goes to the console where Eclipse was launched. 否则,它将转到启动Eclipse的控制台。

Read more here: http://wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F 在此处了解更多信息: http : //wiki.eclipse.org/FAQ_How_do_I_write_to_the_console_from_a_plug-in%3F

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM