要在我开发的插件的控制台中写入,我使用之前找到的这种方法。 我的工作
private static MessageConsole findConsole(String name) {
if (ConsolePlugin.getDefault() == null)
return null;
ConsolePlugin plugin = ConsolePlugin.getDefault();
IConsoleManager conMan = plugin.getConsoleManager();
IConsole[] existing = conMan.getConsoles();
for (int i = 0; i < existing.length; i++)
if (name.equals(existing[i].getName())) {
conMan.showConsoleView(existing[i]);
return (MessageConsole) existing[i];
}
// no console found, so create a new one
MessageConsole myConsole = new MessageConsole(name, null);
conMan.addConsoles(new IConsole[] { myConsole });
return myConsole;
}
public static MessageConsoleStream getMessageStream() {
MessageConsole myConsole = findConsole("console");
if (myConsole != null) {
IWorkbench wb = PlatformUI.getWorkbench();
String id = IConsoleConstants.ID_CONSOLE_VIEW;
return myConsole.newMessageStream();
}
return null;
}
我这样使用:
MessageConsoleStream out = Application.getMessageStream();
out.print("AB");
现在我想从控制台读取。 我该怎么做?
答案 0 :(得分:0)
尝试从getInputStream()
返回的MessageConsole
实例上调用findConsole
并从那里开始。 Read more about the input stream that's returned here.