stackleit
stackleit

Reputation: 284

Setting a Windows environment variable to be read by a Ruby script

My setup: Windows 7, ruby 1.9.3p125 (2012-02-16) [i386-mingw32]

In scratchfile.rb, I have:

puts ENV["TESTVAR"]

At my command prompt, I type:

set TESTVAR = hello
ruby scratchfile.rb

I get the following output:

C:\myrubyproject>

Why don't I see the value 'hello'? Thanks!

Upvotes: 0

Views: 847

Answers (1)

Max
Max

Reputation: 22325

You shouldn't put spaces around =.

> set TESTVAR=hello
> ruby -e 'p ENV["TESTVAR"]'
"hello"

Upvotes: 2

Related Questions