我想在我的红宝石代码中ping一个网站,看到net-ping是一个很好的图书馆.不幸的是,当我尝试gem安装net-ping我得到以下错误:
C:>gem install net-ping
ERROR: Error installing net-ping:
win32-open3 requires Ruby version < 1.9.0.
解决方法
您可以随时执行此操作,并使用正则表达式来解析结果或仅检查退出状态:
ping_count = 10 server = "www.google.com" result = `ping -q -c #{ping_count} #{server}` if ($?.exitstatus == 0) do puts "Device is up!" end
Ping返回值可以检查:
The ping utility returns an exit status of zero if at least one response was heard from the specified host; a status of two if the transmission was successful but no responses were received; or another value (from
<sysexits.h>
) if an error occurred.