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
What Is Java Interface Equivalent in Ruby
What Is the Purpose of "!" and "" at the End of Method Names
What's This &Block in Ruby? and How Does It Get Passed in a Method Here
What Are Some Good Ruby-Based Web Crawlers
How to Replace a Hash Key with Another Key
How Does Load Differ from Require in Ruby
How to Call a Controller'S Method from a View (As We Call from Helper Ideally)
How Would You Parse a Url in Ruby to Get the Main Domain
How to Display Ruby on Rails Form Validation Error Messages One At a Time
Ruby - Net/Http - Following Redirects
Shortcut to Make Case/Switch Return a Value
Setspeed in Selenium Webdriver Using Ruby
Why Doesn't Ruby Find Classes in a Higher Scope When Module Is Specified Using ::
How to Solve This Trouble to Deploy a Rails App to Heroku
Find Number of Months Between Two Dates in Ruby on Rails
How to Calculate the Day of the Week of a Date in Ruby
Running a Command from Ruby Displaying and Capturing the Output