Execute Bash Commands from a Rakefile

Execute bash commands from a Rakefile

I think the way rake wants this to happen is with: http://rubydoc.info/gems/rake/FileUtils#sh-instance_method
Example:

task :test do
sh "ls"
end

The built-in rake function sh takes care of the return value of the command (the task fails if the command has a return value other than 0) and in addition it also outputs the commands output.

How to execute commands within Rake tasks?

This links may help you run command line command into ruby ...

http://zhangxh.net/programming/ruby/6-ways-to-run-shell-commands-in-ruby/

Calling shell commands from Ruby

http://blog.jayfields.com/2006/06/ruby-kernel-system-exec-and-x.html

%x[command].each do |f|
value = f
end

Execute rake command inside bash

klashxx's supposition was correct. It was a permissions/profile issue. I had change my user to root to be able to do other previous tasks and found out that my root was not able to run rake tasks.

This will not be an issue on production server though.

Thanks klashxx

Run Rake on other projects by Shell Script

I thought I already had done this but seems not. The answer was clear and simple: Change directory first.

destination_folder="/Path/of_all_my_clients_app/"
client="client_name"

cd $destination_folder$client
rake tmp:clear assets:clean log:clear RAILS_ENV=production
...

Thanks majioa.

Rails: How to run rake commands using Bash script?

to run the command you need to type:

./reset_db.sh

Regarding the rake command, are you in the folder where the rake should be launched?

Is there any better way to execute several system commands from a rake task?

You could join all those commands into a single command and execute that. Assuming you created an array commands containing all your commands, you could do this:

composite_command = commands.join('; ')
system(composite_command)

If you want execution to stop if any contain errors you could replace the semicolons with double ampersands ampersands:

composite_command = commands.join(' && ')
system(composite_command)

This illustrates what && does:

$ ls foo && echo hi
ls: foo: No such file or directory
$ touch foo
$ ls foo && echo hi
foo
hi

The shell defines failure as the returning of an exit code other than 0.

There is a maximum command length but I expect that it would always be at least 1024.



Related Topics



Leave a reply



Submit