Java starts the dos command to collect notes one
Java starts the dos command to collect information note 1
Import java.io.BufferedReader
Import java.io.IOException
Import java.io.InputStream
Import java.io.InputStreamReader
Import java.util.ArrayList
Import java.util.List
Import org.testng.annotations.Test
Public class Person {
@ Test / / use testng as the entry
Public void doscmd () throws InterruptedException
{
System.out.println (System.getProperty ("os name")); / / determine the current system
Person p = new Person ()
List dL = p.excmd ("adb devices"); / / call function to execute adb devices command
System.out.println (dL.size ())
For (String s:dL) {/ / outputs content through enhanced for loops. Dl---defines the variable, and the dl-- is the content of the adb devices
System.out.println (s); / / output display
}
}
Public List excmd (String cmdString) throws InterruptedException {
List dosCMd = new ArrayList (); / / define a List collection
Process process = null; / / set a Process ID number
Try {
Process = Runtime.getRuntime () .exec (cmdString); / / start the exec command through the built-in function
InputStream in = process.getInputStream (); / / output through the output stream
BufferedReader inR = new java.io.BufferedReader (new InputStreamReader (in))
String line = null
While ((line = inR.readLine ())! = null) / / traverse command line information through while
{
DosCMd.add (line)
}
System.out.println ("removed successfully")
} catch (IOException e) {
System.out.println ("data not available")
E.printStackTrace ()
}
Process.waitFor ()
Process.destroy ()
Return dosCMd
}