# Very basic problem with rake task?

**URL:** <https://www.ruby-forum.com/t/very-basic-problem-with-rake-task/112590>\
**Category:** Rails\
**Created:** [August 21, 2007, 5:50am UTC](https://www.ruby-forum.com/t/very-basic-problem-with-rake-task/112590 "2007-08-21T05:50:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [August 21, 2007, 5:50am UTC](https://www.ruby-forum.com/t/very-basic-problem-with-rake-task/112590/1 "2007-08-21T05:50:06Z")

</div>

I wrote the following rake task to execute the ‘ls’ UNIX command using  
the ‘command’ method in the ‘FileOperation’ module

require ‘rake’  
require ‘rake/testtask’  
require ‘rake/rdoctask’

require ‘FileOperations’  
include FileOperations

namespace :test do  
task :post\_heartrate do  
FileOperations.command ‘ls’  
end  
end

When I run it, I get the following error:  
no such file to load – FileOperations

Then, I get the following error if I take out the ‘require’ line:  
uninitialized constant FileOperations

I know this is a very basic problem. Any suggestions?

Thanks  
Chirag

---

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [August 21, 2007, 4:32pm UTC](https://www.ruby-forum.com/t/very-basic-problem-with-rake-task/112590/2 "2007-08-21T16:32:45Z")

</div>

HI Chirag,

I’m guessing you copied the rake from the middle of a Rails app maybe?  
There is a lot of extra requires that are not “required”.

Here is a rake file that accomplishes what you describe. There were no  
other requires or anything else. This is the defined “Rake File  
Format”.  
Also, Dir.glob is in the Ruby core, so no requires are necessary. :

=== start RakeFile.rb ===  
desc “List Files in current dir.”

task :list\_files do  
Dir.glob(“\*”).each do |d|  
puts d  
end  
end  
=== end RakeFile.rb ===

And the output :  
$ ls -l  
total 1  
-rw-r–r-- 1 mlpf mkgroup-l-d 101 Aug 21 09:26 RakeFile.rb

$ rake -T  
(in /home/mlpf/ruby)  
rake list\_files # List Files in current dir.

$ rake list\_files  
(in /home/mlpf/ruby)  
RakeFile.rb

Here are the references I reviewed:  
[http://rake.rubyforge.org/](http://rake.rubyforge.org/)  
“Rake Tutorial”: [http://docs.rubyrake.org/read/book/1](http://docs.rubyrake.org/read/book/1)  
“Rake Users Guide”: [http://docs.rubyrake.org/read/book/2](http://docs.rubyrake.org/read/book/2)

Hope that helps!  
Peter F.  
[http://fitzgibbons.info](http://fitzgibbons.info)

On 8/20/07, chirag [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> include FileOperations  
> Then, I get the following error if I take out the ‘require’ line:  
> uninitialized constant FileOperations
> 
> I know this is a very basic problem. Any suggestions?
> 
> Thanks  
> Chirag
> 
> >

## – Peter F.

## iPhone – “IT”-ness. href= [Apple’s iPhone could become iconic ‘It Object’ - MacDailyNews](http://www.macdailynews.com/index.php/weblog/comments/apples_iphone_could_become_iconic_it_object)

---

<div class="post-metadata">

**Author:** ![chirag](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/ecccb3/32.png) [@chirag](https://www.ruby-forum.com/u/chirag)\
**Post date:** [August 22, 2007, 7:38pm UTC](https://www.ruby-forum.com/t/very-basic-problem-with-rake-task/112590/3 "2007-08-22T19:38:58Z")

</div>

On 8/20/07, chirag [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> namespace :test do  
> task :post\_heartrate do  
> FileOperations.command ‘ls’  
> end  
> end
> 
> When I run it, I get the following error:  
> no such file to load – FileOperations

FileOperations is part of the guts of Rails.

To run an external command, use the “sh” method which Rake provides:

sh ‘somecommand’

Rake includes the Ruby standard FileUtils and adds a few handy  
extensions, so that’s where you should be starting.

[http://www.ruby-doc.org/stdlib/libdoc/fileutils/rdoc/index.html](http://www.ruby-doc.org/stdlib/libdoc/fileutils/rdoc/index.html)  
[http://rake.rubyforge.org/classes/FileUtils.html](http://rake.rubyforge.org/classes/FileUtils.html)
