如何使用自定义启动配置捕获 Eclipse 插件的控制台输出?

发布于 2024-12-07 09:23:26 字数 1048 浏览 1 评论 0原文

我正在编写一个带有自定义启动配置的 Eclipse 插件,即 LaunchConfigurationDelegate 子类中的 launch() 方法。此方法本质上只是调用 Runtime.exec(),但是当我从 launch() 内写入 System.out 时,它会转到正在调试的 Eclipse 实例的控制台插件,而不是插件实例本身的控制台。我已经分析了该方法的 ILaunchConfigurationILaunch 参数,但找不到它们指定我可以写入的任何输出/错误流的任何地方。

正如教程中所建议的,我有 2 个单独的插件一起运行;一个处理 UI 内容(LaunchConfigurationTabLaunchConfigurationTabGroupLaunchShortcut),另一个包含 LaunchConfigurationDelegate 本身。

我使用这段代码在我的UI插件中创建了一个控制台,我可以从在 UI 代码中。但我不知道如何将非 UI 插件中生成的输出定向到 UI 插件中创建的控制台。

我已阅读这篇文章和< a href="http://waynebeaton.wordpress.com/2006/10/19/displaying-the-console-in-your-rcp-application/" rel="nofollow noreferrer">这个一个,但他们没有指定如何“获取”在 launch() 方法中生成的输出。

任何指示都将非常受欢迎,我被困住了!

I'm writing an Eclipse plugin with a custom launch configuration, i.e. a launch() method inside a subclass of LaunchConfigurationDelegate. This method essentially just calls Runtime.exec(), but when I write to System.out from within launch() it goes to the console of the Eclipse instance which is debugging the plugin, rather than to the console of the plugin instance itself. I've analysed the ILaunchConfiguration and ILaunch arguments to the method but cannot find anywhere that they specify any output/error streams I can write to.

As is recommended in the tutorials, I have 2 separate plugins running together; one which handles the UI stuff (LaunchConfigurationTab,LaunchConfigurationTabGroup,LaunchShortcut,) and the other which contains the LaunchConfigurationDelegate itself.

I created a console in my UI plugin using this code, and I can write to it fine from within the UI code. But I cannot figure out how to direct output generated in my non-UI plugin to the console created in my UI plugin.

I've read this post and this one, but they do not specify how to "get ahold" of the output which is generated within the launch() method in the first place.

Any pointers would be really welcome, I am stuck!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

美煞众生 2024-12-14 09:23:26

好吧,我终于设法让一些东西按如下方式工作:

在我的 LaunchConfigurationDelegate 中,我引入了以下静态方法:

public static void setConsole(PrintStream ps) {
    System.setOut(ps);
    System.setErr(ps);
}

然后在我的 UI 插件的 PerspectiveFactory 中创建控制台时,我按如下方式调用它:

private void createConsole() {
    console = new MessageConsole("My Console", null);
    console.activate();
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });
    MessageConsoleStream stream = console.newMessageStream();

    MyLaunchConfigurationDelegate.setConsole(new PrintStream(stream));
}

这有效,除了每次我关闭 Eclipse 并重新启动它时,控制台都会消失。然而,当我重置视角时,控制台再次出现。显然,我需要在启动时调用该代码,而不是在 PerspectiveFactory 本身中调用。

希望这对某人有帮助..如果有人对最后一个问题(或关于我的一般方法)有一些意见,请发表评论!

Well I finally managed to get something working as follows:

In my LaunchConfigurationDelegate I introduced the following static method:

public static void setConsole(PrintStream ps) {
    System.setOut(ps);
    System.setErr(ps);
}

Then when creating my console in my UI plugin's PerspectiveFactory I call it as follows:

private void createConsole() {
    console = new MessageConsole("My Console", null);
    console.activate();
    ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[]{ console });
    MessageConsoleStream stream = console.newMessageStream();

    MyLaunchConfigurationDelegate.setConsole(new PrintStream(stream));
}

This works, except everytime I close down Eclipse and restart it the console disappears. However when I reset my perspective, the console appears again. So obviously I need that code to be called on startup, not in the PerspectiveFactory itself.

Hope this helps someone.. and if anybody has some input for this last problem (or about my approach in general) please do comment!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文