While line=o.gets break if line idles for to long

Require ‘open3’
app_closed_list=[]
Open3.popen3(“ping google.com”){|i,o,t,p|
While line=o.gets
Puts line
End

if the line is empty for 30 seconds, i would like to force the
application closed and log some info
kill #{p.pid}
app_closed_list<<“app #{p.pid} has been idle for to long”

here a timeout detection, with a select 100ms

=====================
require ‘open3’

app_closed_list=[]
Open3.popen3(“ping -t google.com”){|i,o,t,p|
loop {
if select([o],nil,nil,0.1)
line=o.gets
puts “>”+line
else
puts “timeout”
end
}
}

Oh man I did stumble across this example but couldn’t get it to work.
One more problem

While line=o.gets
Puts line
If line.includes?(“some string found”)
kill #z{p.pid}
End
End

Is there a proper way to kill the application with ruby?

Bigmac T. wrote in post #1167899:

Oh man I did stumble across this example but couldn’t get it to work.

No wonder: spelling of keywords and method names is wrong in the code
you present.

One more problem

While line=o.gets
Puts line
If line.includes?(“some string found”)
kill #z{p.pid}
End
End

We are lacking a lot context here. What are you trying to achieve?

Is there a proper way to kill the application with ruby?

You could start by properly spelling Ruby keywords and method names…

Cheers

robert

Bigmac T. wrote in post #1167899:

Oh man I did stumble across this example but couldn’t get it to work.

?

One more problem

?

… Is there a proper way to kill the application with ruby?

yes : p.kill

but p.Kill will not work :slight_smile:

============
require ‘open3’
prog=“STDOUT.sync=true;%w{please, stop the bigmac, its will break your
head and kill the process}.each_with_index {|w,i| puts w;
sleep(i*0.1);}”
Open3.popen3(“ruby”,"-e", prog) { |i,o,t,p|
loop {
if select([o],nil,nil,1)
puts " "+o.gets
else
puts “kill sub-proces…”
p.kill
puts “killed”
break
end
}
}

ruby p.rb
please,
stop
the
bigmac,
its
will
break
your
head
and
kill
the
kill sub-proces…
killed