Reputation: 91
Issue : I have two applications A & B both running on the same server. I have a script in the filesystem
cd /data/B/
bundle exec rake -T
When i run the script through the rails console of application A it errors as the console loads the gems of A and the rake task fails
eg: system("sh ~/test.sh")
rake aborted!
LoadError: cannot load such file -- log4r
/home/kumolus/api/config/application.rb:9:in `require'
/home/kumolus/api/config/application.rb:9:in `<top (required)>'
/home/kumolus/api/Rakefile:1:in `require'
/home/kumolus/api/Rakefile:1:in `<top (required)>'
(See full trace by running task with --trace)
When i run the script through the unix command line (irrespective of my pwd) it works
cd ~
sh test.sh #works
cd /data/A #my application A's dir
sh ~/test.sh #also works
I need it to work through rails.Any help ? Thanks!
Upvotes: 2
Views: 403
Reputation: 91
Thanks guys for your help, I found a solution its due to bundler default behaviour.
I used with_clean_env method with a block and it gets executed.
Thanks Team Cheers
Upvotes: 2
Reputation: 32955
I think cd'ing to the folder should be sufficient to switch the environment within the shell process which is doing the cd'ing. Try this.
Go into project B and do
which bundle
in the command line, and copy the result somewhere. Then do
which rake
and copy the result of that.
Then, switch to project A and start a rails console. Then try this:
`cd /path/to/projectB; bundle exec rake -T`
If that doesn't work, try this:
`cd /path/to/projectB; <result of doing "which bundle" earlier> exec rake -T`
Then if it still doesn't work, try this:
`cd /path/to/projectB; <result of doing "which bundle" earlier> exec <result of doing "which rake" earlier> -T`
Upvotes: 1