Capturing stdout from C++ library

345 views
Skip to first unread message

obsidian

unread,
Jun 17, 2015, 9:56:01 AM6/17/15
to jna-...@googlegroups.com
I have a C++ library I am accessing using JNA. During operation it prints various pieces of information to the stdout, which I would like to be able to capture within Java. The prints appear on the output, so I assume that it should be possible to do this.

However, I have tried capturing the Java System.out, using System.setOut, and that does not seem to work. Does anybody know a way of capturing the stdout?

Thanks

Wellton Barros

unread,
Jun 17, 2015, 10:45:56 AM6/17/15
to jna-...@googlegroups.com
Hello friend, you must in C ++ must return byte array, and receive as Java byte [].

I hope this helps!

Wellton S. Barros
+55 62 9602-0305

--
You received this message because you are subscribed to the Google Groups "Java Native Access" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jna-users+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Kustaa Nyholm

unread,
Jun 17, 2015, 1:15:39 PM6/17/15
to jna-...@googlegroups.com



On 17 Jun 2015, at 16:56, obsidian <stephe...@gmail.com> wrote:

> I have a C++ library I am accessing using JNA. During operation it prints various pieces of information to the stdout, which I would like to be able to capture within Java. The prints appear on the output, so I assume that it should be possible to do this.


This is not really a Java nor JNA question.

You need to figure out how to do that on the C/C++ side and you can then bring the data over to Java and this is where JNA can help.


How ever, if you are on Unix/Linux/Mac OS you could possibly just pipe the output to a socked and read that directly in Java…come to think of it, you can execute any program from Java directly and capture the output, this would be the easiest if can compile your C++ lib to an application that can be executed.

br Kusti


This e-mail may contain confidential or privileged information. If you are not the intended recipient (or have received this e-mail in error) please notify the sender immediately and destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material in this e-mail is strictly forbidden. We will not be liable for direct, indirect, special or consequential damages arising from alteration of the contents of this message by a third party or as a result of any virus being passed on or as of transmission of this e-mail in general.

Timothy Wall

unread,
Jun 18, 2015, 9:32:35 AM6/18/15
to jna-...@googlegroups.com
Are you using a C or C++ library? manipulating stdout/stderr is different from cout/cerr.

You should look up how to redirect those streams first, then you will better understand how you can perform that manipulation from Java.

It *is* possible to redirect those streams to a file (which then would be easy to read from Java).

Note that Java’s System.out is entirely different from native code’s output buffers. The C or C++ runtimes have their own mechanisms for delivering text output to the terminal, and *that* is what you have to intercept.
Reply all
Reply to author
Forward
0 new messages