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”
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
============
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
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.