Skip to content

Instantly share code, notes, and snippets.

@asmega
Created June 29, 2017 10:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asmega/77f41f967f3fc225cc067eb37ab6bd27 to your computer and use it in GitHub Desktop.
Save asmega/77f41f967f3fc225cc067eb37ab6bd27 to your computer and use it in GitHub Desktop.
wrapper
#!/usr/bin/env ruby
require 'pty'
@script = "./rand.rb"
@interval = 5
def start
puts 'starting'
PTY.spawn(@script) do |read, write, pid|
@pid = pid
last_line = nil
thread = Thread.new do
previous = "unknown"
while true
# puts 'previous', previous
# puts 'last_line', last_line
if previous == last_line
puts 'restart'
`kill #{pid}`
break
else
previous = last_line
sleep(@interval)
end
end
end
read.each do |line|
last_line = line
puts line
end
end
end
while true
start
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment