Setting Windows Enviroment in Ruby Script

I need to set the following windows environment variable at the
beginning of my script:

    set http_proxy=http://10.1.1.1:8080

This works from the command line if I run this command from the CLI
right before I run my script but when I try to shell out and the run
command like this from my ruby script:

    `set http_proxy=http://10.1.1.1:8080`

The environmental variable never gets set.

What is the best way to set an environmental variable in Windows from
ruby?

thanks

jack

···

--
Posted via http://www.ruby-forum.com/.

"set" only sets a variable for the process that invokes "set":

Quoth Microsoft:
"Use the set command to create, change, delete, or display environment variables. The set command alters variables in the current shell environment only."[0]

http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds.mspx?mfr=true

So, your variable gets set, but since the cmd shell expires, it takes the environment variable with it.

You could try setting the variable in the Registry, but I advise against it (not a robust solution for something that is intended to be temporary, and it needs administration privileges).

You could define a Constant in Ruby, though, if only your Ruby script needs it, like so:
HTTP_PROXY = your_proxy_ip_address

···

On 18.12.2009 18:24, jackster the jackle wrote:

I need to set the following windows environment variable at the
beginning of my script:

     set http_proxy=http://10.1.1.1:8080

This works from the command line if I run this command from the CLI
right before I run my script but when I try to shell out and the run
command like this from my ruby script:

     `set http_proxy=http://10.1.1.1:8080`

The environmental variable never gets set.

What is the best way to set an environmental variable in Windows from
ruby?

--
Phillip Gawlowski

ENV['http_proxy'] = "http://10.1.1.1:8080"

That will set the environment variable for your current process and
also will be transfered to the child process spawned by it.

···

On Dec 18, 2:24 pm, jackster the jackle <johnshea...@att.net> wrote:

I need to set the following windows environment variable at the
beginning of my script:

set http\_proxy=http://10.1.1.1:8080

--
Luis Lavena

Thanks alot for the help Luis...that worked perfectly for what I needed.

jack

Luis Lavena wrote:

···

On Dec 18, 2:24�pm, jackster the jackle <johnshea...@att.net> wrote:

I need to set the following windows environment variable at the
beginning of my script:

� � set http_proxy=http://10.1.1.1:8080

ENV['http_proxy'] = "http://10.1.1.1:8080"

That will set the environment variable for your current process and
also will be transfered to the child process spawned by it.

--
Posted via http://www.ruby-forum.com/\.