The following is a method to execute rake tasks from ruby code
:#arguments can be for example db:migrate def call_rake(arguments) if RUBY_PLATFORM =~ /mswin/ rake_cmd = "rake.bat" #very important because windows will break with just "rake" else rake_cmd = "rake" end puts "calling #{rake_cmd} " + arguments puts system("#{rake_cmd} " + arguments) puts $? end
Check out my Bullet on Rails project at Rubyforge.net to see how to call script generate scripts from ruby code.
Comments
Another bit of strangeness with this. If you leave out the extension but redirect the output to a file, like system("rake --tasks > tmp.log"), it works.
I ended up just needing this:
somefile.rb:
rake = 'rake'
arguments= '-f compile.rb'
#puts "Calling #{rake} " + arguments
system("#{rake} " + arguments)