为什么重定向标准输出/标准错误在Android上不工作?

问题描述:

我下载了SDL 1.3和OpenGL ES的在我的Andr​​oid 2.2的设备进行了测试在一起。它工作正常,但我不明白的输出的printf 通话。我想提到在 Android开发者页面下面的命令,但没有 DDMS 在Eclipse和亚行logcat 报道说,程序写入使用字符串的printf 。我就确定了标准输出标记筛选。

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?

这样做是有一个文件的另一种方式 /data/local.prop ,只包含行 log.redirect-标准输入输出=真。也许这工作得更好?另外请注意,标准输出缓冲,所以它可能是您的输出依旧坐在缓冲区,等待刷新。您可以拨打 fflush 手动进行检查。

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.