execute shell command in ruby rake task
There are a few differnt options to execute shell cmd in ruby rake task:
1. exec
2. system
3. backtick “
4. %x{}
%x{} returns back to rake task whereas exec and system does not (exec replace the current process with a new one, system return true or false )
so if you do something like
desc 'example' task :example do exec {cmd_one} exec {cmd_two} end end
cmd two will never get executed. Switch to %x{} instead.
btw, you can run multiple rake task like this
desc 'example' task :example do Rake::Task['name_space:task_one'] Rake::Task['name_space:task_two'] end end
Thanks Eric! That’s exactly what I was looking for.
michal kuklis
July 27, 2009 at 9:19 pm
I know this is an old post, but since I found this via Google it might help someone else.
Another way to execute a shell task in rake is:
sh %{command}
This has the advantage of showing the command that is executed if you do “rake –trace”. Unfortunately, this doesn’t display when you are doing a dry run — one thing I miss from make.
Tim Binder
January 12, 2012 at 10:00 pm