mac java执行adb devices命令
最近在做mac+appium自动化需要通过java获取手机设备id,通过代码需要这样才能获得;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.List;
public class Tet {
public static void main(String[] args) {
Process process = null;
String osName = System.getProperty("os.name
");
String command = "/Users/zhouhaijun/androidsdk/android-sdk-macosx/platform-tools/adb devices"; //sdk所在位置
try
{
process=Runtime.getRuntime().exec(command);
InputStreamReader ir =new InputStreamReader(process.getInputStream());
LineNumberReader input= new LineNumberReader(ir);
String line;
while((line=input.readLine())!=null)
System.out.println(line);
}
catch(IOException e){
System.err.println("IOException"+e.getMessage());
}
System.out.println(osName+"/n");
}
}
本文出自 “知止内明” 博客,请务必保留此出处http://357712148.blog.51cto.com/6440370/1976023
原文:http://357712148.blog.51cto.com/6440370/1976023