Craig Walker Craig Walker - 7 months ago 27
Ruby Question

How can I preserve output color when executing a process in Ruby?

I'm using a helper script to execute


command = "rake spec #{path} #{scope}"
output = `#{command}`
puts output

This works fine, except that I lose all the colors from the
rake rspec
output. The appropriate ANSI codes do not appear to be contained within the

How can I execute a process so that it returns output which includes the text color?

Answer Source

Kernel.exec() gets me the solution I want (colored rspec output), but it does so by replacing my ruby script process with the rspec process. That means I can't do anything with the output or run anything after the rspec call.

That's acceptable in my particular situation, but less than ideal as a general solution. So I'd like a better answer if available.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download