因为你的代码返回的结果是ping命令是否正确运行,而不是ping命令是否返回是否接收到对方返回,所以总是true
检查下api文档,可以看到true和false不是用来表示命令执行结果的:
https://docs.oracle.com/javase/8/docs/api/java/lang/Process.html#waitFor-long-java.util.concurrent.TimeUnit-
Returns:
true if the subprocess has exited and false if the waiting time elapsed before the subprocess has exited.