gpt4 book ai didi

ruby - 在 Ruby 脚本中运行 bundle install?

转载 作者:数据小太阳 更新时间:2023-10-29 07:49:54 25 4
gpt4 key购买 nike

我正在构建一个 Ruby 脚本来遍历多个目录,并在所有目录上运行 git 命令和 bundle install:

dirs = ['~/code1, ~/code2, ~/code3]
dirs.each do |dir|
Dir.chdir(dir) do
`git checkout develop`
`git pull`
`bundle install`
end
end

当我这样做时,git 在正确的目录中运行,但 bundle 程序在与脚本相同的目录中运行。

我尝试使用 bundler 的 --path 选项,但这也没有完成工作。

有什么想法吗?

最佳答案

您的bundle install 子进程可能会继承现有的 Bundler 环境,这会导致意外行为。

来自 Bundler 的文档:

Any Ruby code that opens a subshell (like system, backticks, or %x{}) will automatically use the current Bundler environment. If you need to shell out to a Ruby command that is not part of your current bundle, use the with_clean_env method with a block.

因此,我会尝试这样做:

Bundler.with_clean_env do
`bundle install`
end

关于ruby - 在 Ruby 脚本中运行 bundle install?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24270523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com