Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I redirect JNI console output to Eclipse Console view, when Eclipse plugin uses JNI?

Tags:

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?

like image 337
mahonya Avatar asked Oct 24 '10 14:10

mahonya


1 Answers

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.

like image 112
Kothar Avatar answered Dec 26 '22 05:12

Kothar