Why is redirecting stdout/stderr on android not working?

15,485

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.

Share:
15,485

Related videos on Youtube

trenki
Author by

trenki

Updated on May 15, 2020

Comments

  • trenki
    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 neither DDMS in Eclipse nor adb logcat reports the strings that the program writes using printf. I made sure to filter for the stdout tag.

    $ adb shell stop
    $ adb shell setprop log.redirect-stdio true
    $ adb shell start
    

    What am I missing or doing wrong?

  • trenki
    trenki about 13 years
    adb push local.prop /data/local.prop does not work because of permissions. Do I have to root my device?
  • svdree
    svdree about 13 years
    Hmm, 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
    James Moore almost 12 years
    Does 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
    James Moore almost 12 years
    See my answer to stackoverflow.com/questions/9192749/… for a solution with pipes instead of busybox.

Related