当前 ruby 进程有 bundle setup,所以如果启动的进程执行 ruby 脚本,就会遇到各种复杂情况,所以我需要创建一个进程,但是又能不受当前进程影响
#3 楼 @fsword system("xx") 都算 shelling out
Shelling out When shelling out (using the system or backticks methods, for example), Bundler's environment changes will propogate to the subshell environment. If you desire to shell out without Bundler's environment changes, simply employ the with_clean_env method. It will restore all environment variables to what they were before Bundler was activated. For example:
Bundler.with_clean_env do
`brew install wget`
end
$ ruby -e '`brakeman`' # 可执行
$ bundle exec ruby -e '`brakeman`' # 执行失败,因为Gemfile里面没有brakeman
而 brakeman 是根据管理员配置动态执行的脚本,不可能都放在 Gemfile 里面