Why is redirecting stdout/stderr on android not working?
Solution 1
Another way of doing this is having a file /data/local.prop
, containing just the line log.redirect-stdio=true
. Maybe this works better? Also, note that stdout is buffered, so it could be that your output is still sitting in the buffer, waiting to be flushed. You can call fflush
manually to check this.
Solution 2
According to this presentation, log.redirect-stdio
is for Dalvik output, to redirect C/C++ output (such as printf
), you must install busybox on the device and use its xargs
utility like this:
myprogram | xargs log
This obviously works for code that gets called as a standalone executable. If it's only for debugging purposes, you can write a tiny program to call your library and call that from your application using xargs
.
Related videos on Youtube
trenki
Updated on May 15, 2020Comments
-
trenki almost 4 years
I downloaded SDL 1.3 and tested it together with OpenGL ES on my android 2.2 device. It works fine but I don't get the outputs from the
printf
calls. I tried the commands below as mentioned at the android developer page but neitherDDMS
in Eclipse noradb logcat
reports the strings that the program writes usingprintf
. I made sure to filter for thestdout
tag.$ adb shell stop $ adb shell setprop log.redirect-stdio true $ adb shell start
What am I missing or doing wrong?
-
trenki about 13 yearsadb push local.prop /data/local.prop does not work because of permissions. Do I have to root my device?
-
svdree about 13 yearsHmm, I didn't realize that this would give you trouble on a device. It works fine on the emulator though. I know the emulator is a pain to use, especially with OpenGL, but maybe it's an option for incidental trouble shooting? According to a message by David Turner on the NDK group (see groups.google.com/group/android-ndk/msg/0d37b24df6df7cde ) the stop/setprop/start should be considered unsupported.
-
James Moore almost 12 yearsDoes this work from C? I see stderr output to logcat from java when I do this, but I don't see output from C calls to something like fprintf(stderr, "something").
-
James Moore almost 12 yearsSee my answer to stackoverflow.com/questions/9192749/… for a solution with pipes instead of busybox.