Amélie Pasquier
2010-06-21 07:58:43 UTC
Hello,
What are the solutions to catch the standard outputs stdout/stderr of a DLL
in an interface JNA on Linux and Windows platforms ?
I tried to use the freopen function of C library, like this example :
--------- Interface to C library --------------
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
Pointer freopen (String filename, String mode, Pointer stream);
}
-----------------------------------------------
-------- Main function ------------------
public static void main(String[] args)
{
CLibrary clib = CLibrary.INSTANCE;
clib.freopen("D:/stdout.txt", "w",
NativeLibrary.getInstance((Platform.isWindows() ? "msvcrt" :
"c").getFunction("stdout").getPointer(0));
}
----------------------------------------------
But, on Windows platform, the function "stdout" doesn't exist in msvcrt.dll.
In which library is it ?
Are there other solutions that are easier to implement ?
Thank you.
What are the solutions to catch the standard outputs stdout/stderr of a DLL
in an interface JNA on Linux and Windows platforms ?
I tried to use the freopen function of C library, like this example :
--------- Interface to C library --------------
public interface CLibrary extends Library {
CLibrary INSTANCE = (CLibrary)
Native.loadLibrary((Platform.isWindows() ? "msvcrt" : "c"), CLibrary.class);
Pointer freopen (String filename, String mode, Pointer stream);
}
-----------------------------------------------
-------- Main function ------------------
public static void main(String[] args)
{
CLibrary clib = CLibrary.INSTANCE;
clib.freopen("D:/stdout.txt", "w",
NativeLibrary.getInstance((Platform.isWindows() ? "msvcrt" :
"c").getFunction("stdout").getPointer(0));
}
----------------------------------------------
But, on Windows platform, the function "stdout" doesn't exist in msvcrt.dll.
In which library is it ?
Are there other solutions that are easier to implement ?
Thank you.