Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Execute bash commands from a Rakefile

Tags:

bash

ruby

rake

I would like to execute a number of bash commands from a Rakefile.

I have tried the following in my Rakefile

task :hello do   %{echo "World!"} end 

but upon executing rake hello there is no output? How do I execute bash commands from a Rakefile?

NOTE:This is not a duplicate as it's specifically asking how to execute bash commands from a Rakefile.

like image 936
rudolph9 Avatar asked Mar 20 '12 22:03

rudolph9


People also ask

How are bash commands executed?

When the program being executed is a shell script, bash will create a new bash process using a fork. This subshell reads the lines from the shell script one line at a time. Commands on each line are read, interpreted and executed as if they would have come directly from the keyboard.

How do I run a rake file?

Go to Websites & Domains and click Ruby. After gems installation you can try to run a Rake task by clicking Run rake task. In the opened dialog, you can provide some parameters and click OK - this will be equivalent to running the rake utility with the specified parameters in the command line.


1 Answers

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.

like image 143
Gizmomogwai Avatar answered Sep 17 '22 11:09

Gizmomogwai