[英]How to get Unix timestamp while pinging in Android
I have been able to perform rudimentary pings in android and have been able to get the result using Processes in android. 我已经能够在android中执行基本的ping操作,并且能够使用android中的Processes获得结果。 My code is as follows
我的代码如下
try {
String pingCmd = "ping -s 100 -c 10 " + host;
String pingResult = "";
Runtime r = Runtime.getRuntime();
Process p = r.exec(pingCmd);
BufferedReader in = new BufferedReader(new
InputStreamReader(p.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
text.setText(inputLine + "\n\n");
pingResult += inputLine;
text.setText(pingResult);
}
in.close();
}//try
catch (IOException e) {
System.out.println(e);
}
I am running the following command String pingCmd = "ping -s 100 -c 10 " + host;
我正在运行以下命令
String pingCmd = "ping -s 100 -c 10 " + host;
. 。 I want to get the unix timestamp with each ping I have already tried the following and have not got any results with them:
我想在每次ping时都获得unix时间戳,我已经尝试了以下操作,但没有得到任何结果:
String pingCmd = "ping -s 100 -c 10 " + host+ " -D";
String pingCmd = "ping -s 100 -c 10 " + host+ "| while read pong; do echo "$(date): $pong"; done";
String pingCmd = "ping -s 100 -c 10 " + host+ "| perl -nle 'print scalar(localtime), " ", $_'";
String pingCmd = "ping -s 100 -c 10 " + host+ "| xargs -L 1 -I '{}' date '+%+: {}'";
I don't get any error when I run these just no result in the textview. 当我在textview中运行这些结果时,我没有任何错误。 Please tell me how to get the unix timestamp with every ping
请告诉我如何在每次Ping时获取Unix时间戳
I expect my output to look something like this on each ping 我希望每次ping时的输出看起来都像这样
[1461167279.090372] 108 bytes from ir1.fp.vip.ne1.yahoo.com (98.138.253.109): icmp_seq=1 ttl=51 time=335 ms
您应该查看错误输出流( p.getErrorStream()
),我认为android下的ping无法处理所有这些开关,并在该流上显示错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.