使用 NDK 捕获 stdout/stderr [英] Capturing stdout/stderr with NDK

查看:32
本文介绍了使用 NDK 捕获 stdout/stderr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在移植一些现有的 C 代码以在 Android 上运行.此 C 代码将大量输出写入 stdout/stderr.我需要在内存缓冲区或文件中捕获此输出,然后我可以通过电子邮件发送或以其他方式共享它.

I am porting some existing C code to run on Android. This C code writes lots of output to stdout/stderr. I need to capture this output, either in a memory buffer or a file, so I can then send it by email or otherwise share it.

我怎样才能做到这一点,最好不修改现有的 C 代码?

How can I achieve this, ideally without modifying the existing C code?

注意:这个问题不是关于将输出重定向到 adb 或 logcat;我需要在设备上本地缓冲输出.我知道以下问题似乎无法解决我的问题:

Note: this question is NOT about redirecting the output to adb or logcat; I need to buffer the output locally on the device. I am aware of the following questions, which do not appear to address my query:

推荐答案

stdout 是路径 1,stderr 是路径 2.知道了这一点,你可以建立新的路径,你想成为输出目的地,然后强制它们进入标准输出和/或标准错误.实际示例使用 dup 或 dup2 中有一个示例展示了如何执行此操作.

stdout is path 1 and stderr is path 2. Knowing this, you can establish new path(s) that you want to be the output destination, then coerce them into stdout and/or stderr. There's an example showing how to do this at practical examples use dup or dup2.

这篇关于使用 NDK 捕获 stdout/stderr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆