{"id":3604,"date":"2014-03-29T06:44:04","date_gmt":"2014-03-29T06:44:04","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/parse-out-time-portion-from-ping-results-in-java-collection-of-common-programming-errors\/"},"modified":"2014-03-29T06:44:04","modified_gmt":"2014-03-29T06:44:04","slug":"parse-out-time-portion-from-ping-results-in-java-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/29\/parse-out-time-portion-from-ping-results-in-java-collection-of-common-programming-errors\/","title":{"rendered":"Parse out time portion from ping results in Java-Collection of common programming errors"},"content":{"rendered":"<p>I managed to modify a program to ping peer computer and gets the ping counts. How can I parse out the <code>time = ?ms<\/code> from the ping count results, in real-time?<\/p>\n<p>Code:<\/p>\n<pre><code> public static void main(String[] args) {\n\n    String ip = \"192.168.1.1 -n 10\";\n    String pingResult = \"\";\n\n    String pingCmd = \"ping \" + ip;\n\n    try{\n\n        Runtime r = Runtime.getRuntime();\n        Process p = r.exec(pingCmd);\n\n        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));\n        String inputLine;\n        while ((inputLine = in.readLine()) != null) {\n            System.out.println(inputLine);\n            pingResult += inputLine;\n        }\n        in.close();\n    } catch(Exception e) {\n       System.out.println(e);\n    }\n}\n<\/code><\/pre>\n<p>Output:<\/p>\n<pre><code>Reply from 192.168.1.1: bytes=32 time=2ms TTL=64\nReply from 192.168.1.1: bytes=32 time=4ms TTL=64\nReply from 192.168.1.1: bytes=32 time=2ms TTL=64\nReply from 192.168.1.1: bytes=32 time=2ms TTL=64\nReply from 192.168.1.1: bytes=32 time=20ms TTL=64\nReply from 192.168.1.1: bytes=32 time=9ms TTL=64\nReply from 192.168.1.1: bytes=32 time=3ms TTL=64\nReply from 192.168.1.1: bytes=32 time=2ms TTL=64\nReply from 192.168.1.1: bytes=32 time=2ms TTL=64\nReply from 192.168.1.1: bytes=32 time=3ms TTL=64\n\nPing statistics for 192.168.1.1:\n    Packets: Sent = 10, Received = 10, Lost = 0 (0% loss),\nApproximate round trip times in milli-seconds:\n    Minimum = 2ms, Maximum = 20ms, Average = 4ms\n<\/code><\/pre>\n<p>Am I need to declare a variables and write the &#8220;time = ?ms&#8221; into a textfile using BufferedReader?<\/p>\n<p>I am seeking for hints, thanks.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I managed to modify a program to ping peer computer and gets the ping counts. How can I parse out the time = ?ms from the ping count results, in real-time? Code: public static void main(String[] args) { String ip = &#8220;192.168.1.1 -n 10&#8221;; String pingResult = &#8220;&#8221;; String pingCmd = &#8220;ping &#8221; + ip; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3604","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3604","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=3604"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/3604\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=3604"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=3604"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=3604"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}