简体   繁体   English

如何在Ruby中仅从字符串(EC2盒的控制台输出)中获取新行?

[英]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. 我正在编写一个引导EC2实例并在其上运行一些命令的Rake任务。

AWS' Ruby SDK has: AWS的Ruby SDK具有:

instance.console_output , which returns a String of the full output (from the moment the machine booted until present). instance.console_output ,它返回完整输出的String (从机器启动到存在为止)。

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. 觉得应该在Gem或Ruby库中的某个地方提供用于此目的的工具,但是在Google上搜索并没有产生任何效果。

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. 还有很多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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