ping 命令的退出状态 [英] Exit status of ping command

查看:48
本文介绍了ping 命令的退出状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用 ping 命令时,我的 Perl 脚本卡住了 exit status.

My Perl script gets stuck with an exit status when trying to use the ping command.

推荐答案

根据 这个网站:

如果 ping 完全没有收到任何回复数据包,它将以代码 1 退出.如果同时指定了数据包计数和截止时间,并且在截止时间到达时收到少于计数的数据包,它也会以代码 1 退出.在其他错误时,它会以代码 2 退出.否则它会以代码 0 退出.这使得可以使用退出代码来查看主机是否存活.

If ping does not receive any reply packets at all it will exit with code 1. If a packet count and deadline are both specified, and fewer than count packets are received by the time the deadline has arrived, it will also exit with code 1. On other error it exits with code 2. Otherwise it exits with code 0. This makes it possible to use the exit code to see if a host is alive or not.

列出结果:

  • 成功:代码 0
  • 没有回复:代码 1
  • 其他错误:代码 2

请注意,我链接到的页面上写着Linux/Unix ping 命令",但其他系统,甚至 Linux 和 Unix 的变体,可能会改变此值.

Note that the page I link to says "Linux/Unix ping command", but other systems, or perhaps even variants of Linux and Unix, might vary this value.

如果可能,我会在相关系统上进行测试,以确保您拥有正确的系统.

If possible, I would test on the system in question to make sure you have the right ones.

这篇关于ping 命令的退出状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆