Mac java executes the adb devices command
Mac java executes the adb devices command
Recently, when you are doing mac+appium automation, you need to obtain the id of mobile devices through java, and you need to get it through code.
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"; / / location of 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")
}
}