From: Herman Schultz Date: 2009-08-22T00:13:24+09:00 Subject: Re: Windows ENV object being corrupted Robert Klemme wrote: > 2009/8/12 Herman Schultz : >>> this instead: >> Thanks, Robert.  I can't argue your approach isn't simpler.  In fact, I >> can't remember why we ended up with this. All we really want is the same >> environment that the build system uses available for test and publishing >> systems.  Your suggestion is noted. >> >> However, the problem with ENV still exists.  The problem with spaces and >> large numbers of environment variables.  It's just not in my way >> anymore.  When I get a chance I will use your approach and see if I can >> re-create the problem from just parsing the setEnvironment.bat. > > I was curious and created the test attached but could not provoke any > issues with spaces. I am pretty sure that the size of the environment > is limited somehow but I did not hit a limit or any issues with my > test (at 36,000 and still running). > > What's going on here? > > robert I had chance to get and try your routine. I think the author of this code was trying to get around a recursive problem namely that environment variables are comprised of one or more environment variables. Once I added a routine to resolve this issue I have run without incident. def resolve_variables( field ) value = field value.strip! replace = "" verbose( "In Value = " + value , 5) if value =~ /%(\w+)%/ value.gsub!(/%(\w+)%/) do found = $1 replace = found.gsub("%","") replace = ENV[replace] if replace.nil? abort("??Error: Use of undefined Environment Variable #{found} in #{field}") end verbose("Rep = " + replace, 5) verbose( "Val = " + value , 5) replace end verbose( "Val = " + value , 4) end verbose( "Return -> " + value , 4) return value end File.foreach env_batch_file do |line| if /^\s*SET\s*([^\s=]+)\s*=\s*(.*)$/i =~ line key = $1 value = resolve_variables($2) verbose("ENV[" + key + "] = " + value, 1) ENV[key] = value end end -- Posted via http://www.ruby-forum.com/.