开发者

running " bundle install " command is failure

all,

I use the below command after creating some files in a specific directory. It gets me a error message.

The command

desc "new project_name", "new a project with a name"
def new(project_name = 'my_project')
    directory 'doc', project_name
    path =  Dir.pwd + '/' + project_name
    system("cd #{path}")
    run('bundle install')

    #But th开发者_运维技巧is command is working that makes me so confusing
    #run("cd #{path} && bundle install")

    #puts "Initializing complete"
end

The error

create  aaaaaaa/views/index.slim
create  aaaaaaa/views/layout.slim
run  bundle install from "."
Could not locate Gemfile

I see the rails that runs this commend bundle install directly when it initializes a new project, how the rails can do that? how do i make this command working.


system creates a subprocess and then exits. The subprocess changed directory and then finished, but your script still thinks it's in whatever working directory the process thinks it's in.

If you want to change the working directory of the process running the script, use Dir.chdir().


Rails actually uses a little hack that "prints" the bundle install command to the shell and runs it. Notice the back ticks in the output.

print `"#{Gem.ruby}" -rubygems "#{Gem.bin_path('bundler', 'bundle')}" #{command}`

I also think that the system command doesn't necessarily alter the processes' current working directory (in terms of Thor's run command).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜