ZKX's LAB

sh脚本如何执行adb shell命令 BAT脚本如何自动执行 adb shell 以后的命令?

2021-04-28知识6

如何在android程序中执行adb shell命令 android中执行shell命令有两种方式:1.直接在代码中用java提供的Runtime 这个类来执行命令,以下为完整示例代码。public void execCommand(String command)throws IOException {start the ls command runningString[]args=new String[]{\"sh\",\"-c\",command};Runtime runtime=Runtime.getRuntime();Process proc=runtime.exec(command);这句话就是shell与高级语言间的调用如果有参数的话可以用另外一个被重载的exec方法实际上这样执行时启动了一个子进程,它没有父进程的控制台也就看不到输出,所以需要用输出流来得到shell执行后的输出InputStream inputstream=proc.getInputStream();InputStreamReader inputstreamreader=new InputStreamReader(inputstream);BufferedReader bufferedreader=new BufferedReader(inputstreamreader);read the ls outputString line=\";StringBuilder sb=new StringBuilder(line);while((line=bufferedreader.readLine())。null){System.out.println(line);sb.append(line);sb.append('\\n');}tv.setText(sb.toString());使用exec执行不会等执行成功以后才返回,它会立即返回所以在某些情况下是很要命的(比如复制文件的时候)使用wairFor。

如何在android程序中执行adb shell命令 android中执行shell命令有两种方式:1.直接在代码中用java提供的Runtime 这个类来执行命令,以下为完整示例代码。。

BAT脚本如何自动执行 adb shell 以后的命令? 你可以试一下下面的方法:echo offecho su>;temp.txtecho 其它命令>;>;temp.txtadb shelldel temp.txt

#sh脚本如何执行adb shell命令

随机阅读

qrcode
访问手机版