This are my notes in the fields of computer science and technology. Everything is written with ABSOLUTE NO WARRANTY of fitness for any purpose. Of course, feel free to comment anything.

Thursday, August 14, 2008

Execute a Rake task in another

It is easy to make one task dependent on another, for example:

task :one => [:two, :three]

executes task two, three, then one (I have to test that the order is really this). But how to execute task ":two" in the middle of the code of another task?

Here is the solution:

desc "This task executes task two in its code!"
task :one do

# ... do domething

ENV['PAR1'] = 'xxx'
ENV['PAR2'] = 'yyy'
Rake::Task[ "two" ].execute

# ... do something

end

the ENV assignments and execute call have a similar effect to executing in your shell:

rake two PAR1 = xxx, PAR2 = yyy

Yeah, Rake is a really easy and cool tool for every scripting need...

No comments:

About Me

My photo
Hamburg, Hamburg, Germany
Former molecular biologist and web developer (Rails) and currently research scientist in bioinformatics.