I have a ruby script (Guardfile) that executes a rake command.
guard :shell do
  watch(%r{^manifests\/.+\.pp$}) do |m|
    spec = `rake spec`
    retval = $?.to_i
    case retval
    when 0
       if spec.length > 0 then
          puts spec
          n "#{m[0]} Tests Failed!", 'Rake Spec', :pending         
       else
          puts spec
          n "#{m[0]} Tests Passed!", 'Rake Spec', :pending
       end
    end
end
When I run a 'rake spec' from the command line, outputs are colorized. How could I make it so the output of the ruby script is also colorized?
From command line:

From ruby script:

Update
I was able to sort-of work around the problem by using script
bash command preserve color when piping
spec = `script -q /dev/null rake spec`
This still has the downside of not scrolling the text in real time. While it does preserve the colors, it does not output anything until the very end.
Is there a more native way to do this that will allow for scrolling?
 
     
     
    