From: ara.t.howard@... Date: 2006-07-26T05:57:45+09:00 Subject: Re: Ruby and *NIX environment variables On Wed, 26 Jul 2006, Ben Zealley wrote: > > Erm, *puts on his newbie shirt* I don't seem to have the "session" > package, maybe because this is one-click Ruby for Windows - is it > included by default with the *nix version, or do I need to get it from > somewhere? If the latter, where? I assume > http://rubyforge.org/projects/session is the homepage, but there's > nothing there... > > Cheers > > -- > Ben it's *nix (or msys or cgywin) specific : gem install -r session you don't need session btw. this'll do it too: harp:~ > cat a.rb require 'yaml' require 'tempfile' def tmpfile txt = '' t = Tempfile.new rand.to_s t.write txt t.close t.path end values_sh = tmpfile %q( export KEY=VALUE export date=`date` export foo=bar ) def propagate_env path cmds = <<-cmds echo __before__; ruby -r yaml -e' y ENV.to_hash '; echo __before__ . #{ path } echo __after__; ruby -r yaml -e' y ENV.to_hash '; echo __after__ cmds stdout = IO.popen('sh', 'w+') do |sh| sh.write cmds sh.close_write sh.read end raise "env failure from <#{ path }>" unless $?.exitstatus == 0 before = YAML.load %r/__before__\s*(.*)\s*__before__/mio.match(stdout)[1] after = YAML.load %r/__after__\s*(.*)\s*__after__/mio.match(stdout)[1] updated = {} after.each do |k,v| updated[k] = v if before[k].nil? or before[k] != after[k] end ENV.update updated updated end propagate_env values_sh p ENV['date'] p ENV['foo'] harp:~ > ruby a.rb "Tue Jul 25 14:57:06 MDT 2006" "bar" regards. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama