A Rake executable script, is this the correct approach

J

John Pywtorak

I humbly come to you, because searching, mostly google, has failed to
produce a reference, or someone who has done this.

We traditionally run Rakefile's using either
$ rake
or
$ rake -f my.rake
etc

what if I wanted an executable script, say myscript, which is really a
rake task file, but runs as though it where run as above.
Attempt 1
#!/usr/bin/env rake
task :default do puts "Hello, Rake!" end
FAILED

Attempt 2
#!/usr/bin/env ruby
task :default do puts "Hello, Rake!" end
Rake::Task[:default].invoke
SUCCESS

So, is the latter really the best way? While it works I worry that rake
is somehow not setup the same way if the this had been run the
traditional way. Thanks

--
Windows
Start Here
Frustrating Hanging Crashing
Blue Screen of Death
Reboot
 
J

John Pywtorak

You missed the point and the sha-bang in attempt 1 which was
#!/usr/bin/env rake, not ruby.

I understand what rake is doing, what I want is an executable rake file
without having to explicitly run rake. Thanks

Jason said:
Well, attempt 1 is merely defining the task, the task then has to be run,
which is what's happening in Attempt 2.

When you type `rake` in the command line, what you are really doing is

rake default

Hopefully that explains what's going on.

Jason

I humbly come to you, because searching, mostly google, has failed to
produce a reference, or someone who has done this.

We traditionally run Rakefile's using either
$ rake
or
$ rake -f my.rake
etc

what if I wanted an executable script, say myscript, which is really a
rake task file, but runs as though it where run as above.
Attempt 1
#!/usr/bin/env rake
task :default do puts "Hello, Rake!" end
FAILED

Attempt 2
#!/usr/bin/env ruby
task :default do puts "Hello, Rake!" end
Rake::Task[:default].invoke
SUCCESS

So, is the latter really the best way? While it works I worry that rake
is somehow not setup the same way if the this had been run the
traditional way. Thanks

--
Windows
Start Here
Frustrating Hanging Crashing
Blue Screen of Death
Reboot
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top