本文介绍了编程执行shell命令:为什么它不工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图以编程方式执行新指令ScreenRecorder奇巧。我只是尝试这样的:
I'm trying to programmatically execute the new command "ScreenRecorder" kitkat. I just tried this:
suProcess = Runtime.getRuntime().exec("su");
process = Runtime.getRuntime().exec("screenrecord /sdcard/Folder/Example.mp4");
但不起作用。在文件夹我已经在文件 Example.mp4
,但它是空的(0字节)。为什么?我怎样才能解决这个问题?哪里有问题?如果从终端模拟器我写苏
和preSS进入并写在 screenrecord /sdcard/Folder/Example.mp4$c$c >它完美。 Obvisioully我上运行4.4.2,并在根植终端。
But doesn't work. In the Folder I've the file Example.mp4
but it is empty (0 byte). Why? How can I solve this? Where is the problem? If from terminal emulator I write su
and press enter and after write screenrecord /sdcard/Folder/Example.mp4
it works perfectly. Obvisioully I'm running on 4.4.2 and in a rooted terminal.
推荐答案
试试这个
public static void ScreenRecord() throws Exception
{
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命令:为什么它不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!