Nested Rails Files

J

Joe Wirtley

I'm having trouble making nested Rakefiles work. Say I have the
following:

+ Raketest
Rakefile
+ Child
Rakefile

This is a Raketest folder containing a rakefile, and a child folder
containing a different rakefile. In the Raketest folder, I have the
following Rakefile:

task :default do
sh "cd Child;rake"
end

The Child folder under this has the following Rakefile:

task :default do
puts "Child Rake Default task"
end

The following shows the result of running rake first in the child
folder, then in the Raketest folder:

C:\Raketest\Child>rake
(in C:/Raketest/Child)
Child Rake Default task

C:\Raketest\Child>cd ..

C:\Raketest>rake
cd Child;rake
(in C:/Raketest)
The system cannot find the path specified.
rake aborted!
Command failed with status (1): [cd Child;rake...]
C:/Raketest/rakefile.rb:2
(See full trace by running task with --trace)

When I run rake in the child folder, it works. When I run rake in the
Raketest folder, I get the "The system cannot find the path specified."
message. So what am I missing?

Just for good measure, I uninstalled all versions of Rake (via gem) then
installed the latest version, which didn't change anything.

I've attached my zipped contrived sample. I'd appreciate any help.

Attachments:
http://www.ruby-forum.com/attachment/1474/Raketest.zip
 
M

Mark Bush

Joe said:
When I run rake in the child folder, it works. When I run rake in the
Raketest folder, I get the "The system cannot find the path specified."
message. So what am I missing?

On UNIX (MacOS):
$ cat lib/tasks/Raketest/Rakefile
task :default do
sh "cd Child;rake"
end
$ cd lib/tasks/Raketest/
$ rake
(in /Users/bush/Src/Rails/sample/lib/tasks/Raketest)
cd Child;rake
(in /Users/bush/Src/Rails/sample/lib/tasks/Raketest/Child)
Child Rake Default task
$ rake --version
rake, version 0.8.1

My guess is that it has something to do with the way OS commands are
being executed under Windows. Can you run "cd Child; rake" like that
from the Windows prompt and get the right thing?
 
D

Daniel Schömer

Mark said:
Joe said:
When I run rake in the child folder, it works. When I run rake in the
Raketest folder, I get the "The system cannot find the path specified."
message. So what am I missing?
[...]

My guess is that it has something to do with the way OS commands are
being executed under Windows. Can you run "cd Child; rake" like that
from the Windows prompt and get the right thing?

For Windows cmd.exe, you can't use ';' to separate commands. You
have to use '&' to unconditionally them one after the other.

sh "cd Child & rake" # Windows only

Maybe '&&' will work on Unix and Windows.

sh "cd Child && rake"

Daniel
 
J

Joe Wirtley

Daniel said:
Mark said:
Joe said:
When I run rake in the child folder, it works. When I run rake in the
Raketest folder, I get the "The system cannot find the path specified."
message. So what am I missing?
[...]
For Windows cmd.exe, you can't use ';' to separate commands. You
have to use '&' to unconditionally them one after the other.

sh "cd Child & rake" # Windows only

Maybe '&&' will work on Unix and Windows.

sh "cd Child && rake"

Daniel

Thanks to both of you. I knew it had to be something simple. Both '&'
and '&&' appear to work on Windows.
 

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,774
Messages
2,569,598
Members
45,152
Latest member
LorettaGur
Top