Java Boot DOS command collection note one

Source: Internet
Author: User

Java Boot DOS command gather information note one

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 entrance

public void Doscmd () throws Interruptedexception

{

System.out.println (system.getproperty ("OS Name")); Judging the current system

Person p = new person ();

list<string> DL = p.excmd ("adb devices"); Calling the function to execute the ADB devices command

System.out.println (Dl.size ());

for (String s:dl) {//through enhanced for loop output content. s--defining variables, dl--for ADB devices content

System.out.println (s); Output display

}

}

Public list<string> excmd (String cmdstring) throws Interruptedexception {

list<string> doscmd = new arraylist<string> (); Define a list collection

process process = NULL; Set a process ID number

try {

Process = Runtime.getruntime (). exec (cmdstring); Start the EXEC command with built-in functions

InputStream in = Process.getinputstream (); Output stream through output

BufferedReader InR = new Java.io.BufferedReader (new InputStreamReader (in));

String line = null;

while (line = Inr.readline ()) = null)//through while traversing command lines information

{

Doscmd.add (line);

}

System.out.println ("successfully removed");

} catch (IOException e) {

SYSTEM.OUT.PRINTLN ("Data cannot be obtained");

E.printstacktrace ();

}

process.waitfor ();

Process.destroy ();

return doscmd;

}


This article is from the "Know the Ming" blog, please be sure to keep this source http://357712148.blog.51cto.com/6440370/1981485

Java Boot DOS command collection note one

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.