简体   繁体   English

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

[英]How to capture console output of Eclipse plugin with custom Launch Configuration?

I'm writing an Eclipse plugin with a custom launch configuration, ie a launch() method inside a subclass of LaunchConfigurationDelegate . 我正在编写一个带有自定义启动配置的Eclipse插件,即LaunchConfigurationDelegate子类中的launch()方法。 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. 这个方法本质上只是调用Runtime.exec() ,但是当我从launch()内部写入System.out时,它会进入调试插件的Eclipse实例的控制台,而不是插件实例本身的控制台。 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. 我已经分析了该方法的ILaunchConfigurationILaunch参数,但无法找到任何指定我可以写入的输出/错误流的地方。

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. 一个处理UI东西( LaunchConfigurationTabLaunchConfigurationTabGroupLaunchShortcut ),另一个包含LaunchConfigurationDelegate本身。

I created a console in my UI plugin using this code , and I can write to it fine from within the UI code. 我使用这段代码在我的UI插件中创建了一个控制台,我可以在UI代码中写得很好。 But I cannot figure out how to direct output generated in my non-UI plugin to the console created in my UI plugin. 但我无法弄清楚如何将我的非UI插件中生成的输出定向到我的UI插件中创建的控制台。

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. 我读过这篇文章这一个 ,但他们没有规定如何“得到阿霍德”,这是中产生的输出的launch()摆在首位方法。

Any pointers would be really welcome, I am stuck! 任何指针都会非常受欢迎,我被困住了!

Well I finally managed to get something working as follows: 好吧,我终于设法得到了如下工作:

In my LaunchConfigurationDelegate I introduced the following static method: 在我的LaunchConfigurationDelegate我介绍了以下静态方法:

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: 然后在我的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));
}

This works, except everytime I close down Eclipse and restart it the console disappears. 这是有效的,除非我每次关闭Eclipse并重新启动它时控制台都会消失。 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. 显然我需要在启动时调用该代码,而不是在PerspectiveFactory本身。

Hope this helps someone.. and if anybody has some input for this last problem (or about my approach in general) please do comment! 希望这可以帮助某人..如果有人对这最后一个问题(或者我的方法一般)有一些意见,请做评论!

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

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