Search code examples
luaexit-code

how to read a numerical result from f: close ()


I'm a terrible beginner:

f = io.popen("ping -c 2 -t 5 192.168.0.1")
l = f:read("*a")
f:close()       
if f==0 then print ("active")
else print ("off")
end

enter image description here


Solution

  • local f = io.popen("ping -c 2 -t 5 192.168.0.1")
    local l = f:read("*a")
    f = f:close()
    if f then print ("active") else print ("off") end