Android 终端和日志转储

发布于 2024-09-30 18:28:46 字数 505 浏览 0 评论 0原文

我正在尝试从 Android 活动以编程方式发送终端命令。目前我正在使用如下内容:

Process process = null;
    DataOutputStream os = null;
    process = Runtime.getRuntime().exec("su");
    os = new DataOutputStream(process.getOutputStream());
    os.writeBytes("./data/program1\n");
    os.writeBytes("./data/program2\n");
    os.writeBytes("exit\n");
    os.flush();

但是,我的程序1未能成功运行,我相信这是由于用户权限不足造成的。现在我的问题是:

有谁知道如何将终端转储到文件并将其保存在手机或 SD 卡上?该程序正在绑定到终端以向其提供命令,我想知道一种以其他方式打开连接并访问(通常在终端屏幕上显示的内容)输出的方法。

I am trying to send terminal commands programmaticly from an android activity. At the moment I'm using something like the following:

Process process = null;
    DataOutputStream os = null;
    process = Runtime.getRuntime().exec("su");
    os = new DataOutputStream(process.getOutputStream());
    os.writeBytes("./data/program1\n");
    os.writeBytes("./data/program2\n");
    os.writeBytes("exit\n");
    os.flush();

However, my program1 is failing to run successfully and I believe it is due to inadequate user permissions. Now for my question:

Does anyone know how I can dump the terminal to a file and save it on the phone or sdcard? The program is tying into the terminal to feed it commands, I want to know a way to open a connection the otherway and access the (what is normally visual on a terminal screen) output.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

忘年祭陌 2024-10-07 18:28:46

请参阅终端应用程序的来源,因为它是双向的。

遗憾的是,运行 shell 命令或启动本机进程并不是 Android 官方支持的部分,因此无法保证未来的稳定性。

See the sources for the Terminal application, as that is bidirectional.

Sadly, running shell commands or launching native processes is not an officially supported part of android, so no future stability is guaranteed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文