为什么在 Android 上重定向 stdout/stderr 不起作用?
我下载了 SDL 1.3 并在我的 android 2.2 设备上将其与 OpenGL ES 一起进行了测试。它工作正常,但我没有从 printf
调用中获得输出。我尝试了 android 开发人员页面 但 Eclipse 中的 DDMS 和 adb logcat 都不会报告程序使用 printf 写入的字符串。我确保过滤 stdout
标记。
$ adb shell stop
$ adb shell setprop log.redirect-stdio true
$ adb shell start
我错过了什么或做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
根据此演示文稿,
log.redirect-stdio
用于Dalvik输出,要重定向C/C++输出(例如printf
),您必须在设备上安装busybox并使用其xargs 像这样的实用程序:
这显然适用于作为独立可执行文件调用的代码。如果仅用于调试目的,您可以编写一个小程序来调用您的库,并使用 xargs 从应用程序中调用该库。
According to this presentation,
log.redirect-stdio
is for Dalvik output, to redirect C/C++ output (such asprintf
), you must install busybox on the device and use itsxargs
utility like this: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
.另一种方法是创建一个文件
/data/local.prop
,其中仅包含行log.redirect-stdio=true
。也许这效果更好?另请注意,stdout 是缓冲的,因此您的输出可能仍位于缓冲区中,等待刷新。您可以手动调用 fflush 来检查这一点。Another way of doing this is having a file
/data/local.prop
, containing just the linelog.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 callfflush
manually to check this.