-
-
Save asmega/77f41f967f3fc225cc067eb37ab6bd27 to your computer and use it in GitHub Desktop.
wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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