【Appium】eclipse+appium如何执行adb命令

前提:配置好环境jdk+sdk等等执行代码封装runtime方法,调用runtime方法即可执行adb命令,runtime(“adb 命令”)public static void runtime(String adb) throws IOException { Process p = Runtime.getRuntime().exec(adb); //Process p = ...
摘要由CSDN通过智能技术生成

前提:配置好环境jdk+sdk等等
执行代码
封装runtime方法,调用runtime方法即可执行adb命令,runtime(“adb 命令”)

public static void runtime(String adb) throws IOException {
		Process p = Runtime.getRuntime().exec(adb);
	     //Process p = Runtime.getRuntime().exec("cmd.exe /c dir");
	        final InputStream is1 = p.getInputStream();
	        new Thread(new Runnable() {
	            public void run() {
	                BufferedReader br = new BufferedReader(new InputStreamReader(is1));
	                try{
	                while(br.readLine() != null) ;
	                }
	                catch(Exception e) {
	         e.printStackTrace();
	                }
	            }
	        }).start(); // 启动单独的线程来清空p.getInputStream()的缓冲区
	        InputStream is2 = p.getErrorStream();
	       BufferedReader br2 = new BufferedReader(new InputStreamReader(is2)); 
	        StringBuilder buf = new StringBuilder(); // 保存输出结果流
	        String line = null;
	        while((line = br2.readLine()) != null) buf.append(line); // 
	        System.out.println("输出结果为:" + buf);
	}

在测试时发现ecplise执行runtime执行adb命令会报adb server version (41) doesn’t match this client (40)
是因为c盘中有adb,可以用adb version 查看C盘中的adb版本,将自己配置的sdk中的adb版本,替换掉c盘中的adb版本即可

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值