Ruby 相当于 golang 中的 syscall.Exec
Ruby equivalent of syscall.Exec in golang
我想使用 ruby 以编程方式设置环境变量。在 Golang 中我们有
syscall.Exec(os.Getenv(SHELL), []string{os.Getenv(SHELL)}, updated)
这会打开一个新的默认值 shell,其中包含更新后的变量。因此,我们执行 go 程序的终端将为会话保留这些变量。
我是 ruby 的新手,无法在那里找到等效项。请帮助我。
对于get/set环境变量,你可以使用ENV
hash, then to make system calls, where you could see the standard output (not as ` that will return you the output as a string), you could call system
。
默认 shell 应该在 ENV['SHELL']
中可用,所以你需要的应该是这样的:
ENV['FOO'] = '123' # FOO will last for the entire ruby session
system({'BAR' => '456'}, ENV['SHELL']) # BAR will last until system call has finished
system(ENV['SHELL']) # Here, only FOO will be available, not BAR
我想使用 ruby 以编程方式设置环境变量。在 Golang 中我们有
syscall.Exec(os.Getenv(SHELL), []string{os.Getenv(SHELL)}, updated)
这会打开一个新的默认值 shell,其中包含更新后的变量。因此,我们执行 go 程序的终端将为会话保留这些变量。
我是 ruby 的新手,无法在那里找到等效项。请帮助我。
对于get/set环境变量,你可以使用ENV
hash, then to make system calls, where you could see the standard output (not as ` that will return you the output as a string), you could call system
。
默认 shell 应该在 ENV['SHELL']
中可用,所以你需要的应该是这样的:
ENV['FOO'] = '123' # FOO will last for the entire ruby session
system({'BAR' => '456'}, ENV['SHELL']) # BAR will last until system call has finished
system(ENV['SHELL']) # Here, only FOO will be available, not BAR