当Eclipse插件使用JNI时,如何将JNI控制台输出重定向到Eclipse控制台视图? [英] How can I redirect JNI console output to Eclipse Console view, when Eclipse plugin uses JNI?

查看:286
本文介绍了当Eclipse插件使用JNI时,如何将JNI控制台输出重定向到Eclipse控制台视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Eclipse插件(A),它有另一个插件(B)的依赖。插件B只是一个jar包,它包含一个本地dll,并执行jni功能。
给定这个设置,我在A的Activator类的start方法中有以下代码:

I have an Eclipse plugin (A) which has a dependency on another plugin (B). Plugin B is simply a wrapper around a jar, which contains a native dll, and performs jni functionality. Given this setup, I have the following code in A's Activator class's start method:

MessageConsole jniConsole = new MessageConsole("Opereffa Output", null);
ConsolePlugin.getDefault().getConsoleManager().addConsoles(new IConsole[] { jniConsole });
ConsolePlugin.getDefault().getConsoleManager().showConsoleView(jniConsole);
MessageConsoleStream stream = jniConsole.newMessageStream();
System.setOut(new PrintStream(stream));
System.setErr(new PrintStream(stream));

当插件A执行其功能时,任何使用System.out实际上都会转到Eclipse中的控制台。但JNI使用的本地代码也写入输出流,我不能抓住。
在开发期间,JNI的输出将转到已启动运行实例的Eclipse实例的控制台,该实例包含插件。

When plugin A performs its functionality, any use of System.out actually goes to the console within Eclipse. But native code used by JNI also writes to output stream, which I can't grab. During development, output from JNI goes to the console of the Eclipse instance which has launched the running instance, which contains the plugins.

那么如何在控制台中抓取JNI输出和显示?

So how do I grab the JNI output and display in the console?

推荐答案

您可以尝试使用 freopen 来将stdout重定向到完全相同的方式和你在Java中一样,但在本机端。问题是如果你使用它在你自己的插件(使用一个新的JNI DLL),这可能会工作:它可能需要使用从dll做控制台输出,我不知道流之间的交互DLL 。如果stdout引用了整个进程的共享流,也许会工作。

You could try using freopen to redirect stdout in exactly the same way as you do in Java, but on the native side. The question is whether this would work if you used it in your own plugin (with a new JNI dll): it may need to be used from within the dll doing the console output, I've no idea of the interaction between streams across DLLs. If stdout refers to a shared stream for the whole process, maybe it would work.

这篇关于当Eclipse插件使用JNI时,如何将JNI控制台输出重定向到Eclipse控制台视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆