Use something like this to redirect stderr to the pipe. Ask the reader on the other side of the pipe to write logcat:
extern "C" void Java_com_test_yourApp_yourJavaClass_nativePipeSTDERRToLogcat(JNIEnv* env, jclass cls, jobject obj) { int pipes[2]; pipe(pipes); dup2(pipes[1], STDERR_FILENO); FILE *inputFile = fdopen(pipes[0], "r"); char readBuffer[256]; while (1) { fgets(readBuffer, sizeof(readBuffer), inputFile); __android_log_write(2, "stderr", readBuffer); } }
You want to run this in your thread. I deploy the thread in Java and then the Java thread calls this NDK code as follows:
new Thread() { public void run() { nativePipeSTDERRToLogcat(); } }.start();
James Moore Jun 13 2018-12-12T00: 00Z
source share