Android ping command-Runtime

Source: Internet
Author: User

Code:

1      PublicString Run (String _strsip)throwsException2     {3String Strrst = "";4         Try5         {6String str = "Ping-c 1" +_strsip;7Runtime runtime =runtime.getruntime ();8Process Process =runtime.exec (str);9 Ten             //wait for the process to finish executing One             if(Process.waitfor ()! = 0) A             { -                 //If the process does not run a result of 0, it indicates that the process exited with an error -                 //get error output from process instance theInputStream Streamerr =Process.geterrorstream (); -                 //Do something -                  -Strrst =inputstream2string (streamerr); +                 if(Streamerr! =NULL) - streamerr.close (); +                  A                 if(Strrst.isempty ()) at                 { -InputStream streamin =Process.getinputstream (); -Strrst =inputstream2string (streamin); -                     if(StreamIn! =NULL) - streamin.close (); -                      in                     if(Strrst.isempty ()) -Strrst = "failed:ping Failed."; to                 } +                 returnStrrst; -             } the              *InputStream streamin =Process.getinputstream (); $Strrst =inputstream2string (streamin);Panax Notoginseng             if(StreamIn! =NULL) - streamin.close (); the              +             if(Strrst.isempty ()) AStrrst = "Succeed:ping failed."; the         } +         Catch(Exception ex) -         { $             //ex.printstacktrace (); $StringWriter SW =NewStringWriter (); -PrintWriter PW =NewPrintWriter (SW); - ex.printstacktrace (PW); theStrrst = "ERR:" +sw.tostring (); -         }Wuyi         returnStrrst; the}

Android ping command-Runtime

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.