如何写亚行外壳赞扬java.lang.Runtime.getRuntime()? [英] How to write adb shell commend in java.lang.Runtime.getRuntime()?
本文介绍了如何写亚行外壳赞扬java.lang.Runtime.getRuntime()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用adb连接电脑设备,并做一些检查。
所以,我尝试使用
java.lang.Runtime.getRuntime()。EXEC(CMD)
获得亚洲开发银行
壳导致了我的计划。
但我不知道怎么写了亚行外壳表彰在 EXEC
通话,
是这样的:
I need to use adb connect pc to device and do some checking.
So I try to use
java.lang.Runtime.getRuntime().exec(cmd)
to get adb
shell result into my program.
But I don't know how to write the adb shell commend in the exec
call,
something like:
String cmd =adkHome + "adb.exe -s " + device + " shell ls";
然后 CD数据/应用程序
我如何做到这一点?
推荐答案
这可能是你在找什么?
This may be what you're looking for?
String cmd = "adb shell ls";
String cmdreturn = "";
Runtime run = Runtime.getRuntime();
Process pr = run.exec(cmd);
pr.waitFor();
BufferedReader buf = new BufferedReader(new InputStreamReader(pr.getInputStream()));
while ((line=buf.readLine())!=null) {
System.out.println(cmdreturn);
}
至于在shell preforming行动,我会建议写你执行shell脚本。在这种情况下,而不是
As far as preforming actions in a shell, I would recommend writing a shell script that you execute. In this case instead of
String cmd = "adb shell ls";
将其替换
String cmd = "shellscript.sh";
干杯!
这篇关于如何写亚行外壳赞扬java.lang.Runtime.getRuntime()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文