在 Ruby 中打印命令结果时,如何保留命令的*彩色*输出结果?
事情是这样的:
我通过调用这样的命令从 ruby 文件运行一堆 Cucumber 测试:
result = `bundle exec cucumber tests/specs/features`
[...] # do stuff with it
puts result
现在命令的结果有这些漂亮的颜色,通过仅查看而不阅读它来告诉我很多关于通过和失败测试的信息。但是:当我这样输出结果时,着色就消失了!
有什么方法可以做到这一点而不丢失颜色吗?
Here's the thing:
I run a bunch of Cucumber tests from a ruby file by calling the command like this:
result = `bundle exec cucumber tests/specs/features`
[...] # do stuff with it
puts result
Now the result of the command has these nice colors telling me a lot about passing and failing tests by just looking at it without reading. But: when I put the result like this, the coloring is gone!
Is there any way of doing this without losing the coloring?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看看这个 和 这个问题,它们是关于是同样的事情,但是用的是 rspec 而不是 cucumber。
Take a look at this and this questions, they are about just the same thing but with
rspec
instead ofcucumber
.