Setting Windows Enviroment in Ruby Script

  • Thread starter jackster the jackle
  • Start date
J

jackster the jackle

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
 
P

Phillip Gawlowski

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?

"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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top