从机器人执行shell命令 [英] execute shell command from android

查看:232
本文介绍了从机器人执行shell命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从应用程序模拟器终端执行这个命令(你可以找到它在谷歌播放)在此应用程序我写和preSS <大骨节病>输入,这样写:

I'm trying to execute this command from the application emulator terminal (you can find it in google play) in this app i write su and press enter, so write:

screenrecord --time限制10 /sdcard/MyVideo.mp4

和preSS再次<大骨节病>输入和使用A​​ndroid的奇巧的新功能开始屏幕的记录。

and press again enter and start the recording of the screen using the new function of android kitkat.

所以,我尝试使用这种从Java执行相同的code:

so, i try to execute the same code from java using this:

Process su = Runtime.getRuntime().exec("su");
Process execute = Runtime.getRuntime().exec("screenrecord --time-limit 10 /sdcard/MyVideo.mp4");

但是,不要工作,因为没有创建的文件。很显然,我是一个植根设备安装Android的奇巧上运行。问题出在哪里?我该如何解决?因为从终端仿真作品和在Java中不?

But don't work because the file is not created. obviously i'm running on a rooted device with android kitkat installed. where is the problem? how can i solve? because from terminal emulator works and in Java not?

推荐答案

您应该抓住进程刚刚推出的标准输入并记下命令在那里,否则您当前 UID

You should grab the standard input of the su process just launched and write down the command there, otherwise you are running the commands with the current UID.

尝试是这样的:

try{
    Process su = Runtime.getRuntime().exec("su");
    DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());

    outputStream.writeBytes("screenrecord --time-limit 10 /sdcard/MyVideo.mp4\n");
    outputStream.flush();

    outputStream.writeBytes("exit\n");
    outputStream.flush();
    su.waitFor();
}catch(IOException e){
    throw new Exception(e);
}catch(InterruptedException e){
    throw new Exception(e);
}

这篇关于从机器人执行shell命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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