运行”捆绑安装”命令失败

发布于 2024-12-10 09:55:12 字数 695 浏览 1 评论 0原文

所有,

我在特定目录中创建一些文件后使用以下命令。它给我一条错误消息。

命令

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 this command is working that makes me so confusing
    #run("cd #{path} && bundle install")

    #puts "Initializing complete"
end

错误

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

我看到rails在初始化新项目时直接运行此命令bundle install,rails如何做到这一点?我如何使这个命令起作用。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

潇烟暮雨 2024-12-17 09:55:12

系统 创建子进程然后退出。子进程更改了目录然后完成,但您的脚本仍然认为它位于进程认为它所在的任何工作目录中。

如果您想更改运行脚本的进程的工作目录,请使用 Dir.chdir()

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().

满意归宿 2024-12-17 09:55:12

Rails 实际上使用了一个小技巧,将捆绑安装命令“打印”到 shell 并运行它。请注意输出中的反引号。

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

我还认为系统命令不一定会改变进程的当前工作目录(就 Thor 的运行命令而言)。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文