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.
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?
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.
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.