How do you run a Rake task?
require "rake"
def capture_stdout
s = StringIO.new
oldstdout = $stdout
$stdout = s
yield
s.string
ensure
$stdout = oldstdout
end
Rake.application.rake_require "metric_fetcher", ["../../lib/tasks"]
results = capture_stdout {Rake.application["metric_fetcher"].invoke}
Tags: ruby rake command-line-interface
Source: By Mando Escamilla as answer to the question
This code snippet was collected from stackoverflow, and is licensed under CC BY-SA 3.0
Related code-snippets:
- When to use lambda and Proc.new?
- What is the best way to fix 'Unprocessed view path found' error with ExceptionNotifier plugin in rails 2.1?
- How can I modify a.xfdl file?
- How do I call shell commands in Ruby?
- How can I reverse DNS for Ruby?
- In Ruby, I can map multiple arrays and values from one array to the other.
- What are the pros and cons of using MySQL instead of SQLite for Rails web development?
- How do I update Ruby Gems from behind a proxy (ISA-NTLM)?
- How do I create a class using Singleton Design Pattern in Ruby?
- If grep the file, but show several surrounding lines?
- Why doesn't Ruby have a StringBuffer?
- How do I write a command line program?
- Ruby mixins and calling super methods. Ruby calls and super methods, Ruby calls and Ruby mixins and calls super methods. Ruby calls and super methods.
- Drawing Library for Ruby.
- What are some possible solutions for sqlite3-ruby-1.2.2 not working on OS X?