简体   繁体   中英

How do I get only the new lines from a string (an EC2 box' console output) in Ruby?

I am writing a Rake task that boots an EC2 instance and runs some commands on it.

AWS' Ruby SDK has:

instance.console_output , which returns a String of the full output (from the moment the machine booted until present).

What I really want is the "diff" between the last output and the current, so that I can just print the new lines to my local console.

I feel like there should be a tool for this somewhere in a Gem or Ruby library, but searching on Google has yielded nothing.

Any help, or am I stuck doing:

total = output.lines.length
new_lines = total - last
puts output.lines[-1..new_lines].to_a.join
last = total

in a loop?

Check out...

These are just a few that I've come across. There are many others.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM