Ruby:我可以更新系统环境变量吗?

时间:2022-03-31 23:02:38

Is there a way to update a system's PATH variable through Ruby, permanently? I have the following:

有没有办法永久地通过Ruby更新系统的PATH变量?我有以下内容:

envPath = ENV["PATH"].dup
if envPath.include? "C:\\oracle\\product\\11.2.0\\client_1\\bin;" then
    envPath.slice! "C:\\oracle\\product\\11.2.0\\client_1\\bin;"
    ENV["PATH"] = envPath
    puts ENV["PATH"]
end

This successfully removes the variable I want to, but only for the current window - not permanently.

这成功删除了我想要的变量,但仅限于当前窗口 - 不是永久性的。

1 个解决方案

#1


1  

It's more a question about general computing and process behaviour not ruby special.

这是一个关于通用计算和流程行为的问题,而不是特殊的ruby。

No this is not possible during runtime. Only a father process can configure the environment of it's child before start. Changing the environment of the father process or other processes during runtime isn't supported by any OS.

在运行期间,这是不可能的。只有父进程才能在启动之前配置其子进程的环境。任何操作系统都不支持在运行时更改父进程或其他进程的环境。

#1


1  

It's more a question about general computing and process behaviour not ruby special.

这是一个关于通用计算和流程行为的问题,而不是特殊的ruby。

No this is not possible during runtime. Only a father process can configure the environment of it's child before start. Changing the environment of the father process or other processes during runtime isn't supported by any OS.

在运行期间,这是不可能的。只有父进程才能在启动之前配置其子进程的环境。任何操作系统都不支持在运行时更改父进程或其他进程的环境。