Note: I'm new to Ruby and so the terminology and/or syntax below may be wrong.
Is there a way to watch STDOUT my ruby process without blocking the rest of my code? Something like:
$stdout.read_lines {|line| // This block is executed on each line logged via `puts`
do_something() if line == 'some interesting string'
}
puts 'Hello world'
puts 'some interesting string' // This would cause the `do_something` line to be executed
I have seen examples where a new process can be created and watched in a similar fashion, but none where the current process's stdout was being watched.
Many thanks.
Edit:
Specifically I am looking to execute some code when this line is executed in my Vagrant setup: https://github.com/cogitatio/vagrant-hostsupdater/blob/master/lib/vagrant-hostsupdater/HostsUpdater.rb#L103
It looks like the message is logged to @ui which I believe is an instance this module https://github.com/hashicorp/vagrant/blob/master/lib/vagrant/ui.rb