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));
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.
So how do I grab the JNI output and display in the console?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With