Robert Klemme wrote in post #1128024:
> On Tue, Nov 19, 2013 at 1:08 PM, Robert Klemme
> <shortcutter / googlemail.com> wrote:
>>>>> For the attached test case, I wrote ruby as below, but seems don't work.
>> My bad. This is embarrassing.  I am sorry.
> I still owe you a proper reply.  Here it is:
>
> $ ./test.rb
> a = Linux
> $ cat test.rb
> #!/usr/bin/env ruby
>
> IO.popen(['csh', '-c', 'source test.csh && setenv']) do |io|
>  io.each_line do |line|
>    if %r{^([^=]+)=(.*)$} =~ line
>      ENV[$1] = $2
>    else
>      warn "Cannot read line %p" % line
>    end
>  end
> end
>
> puts "a = #{ENV['SYSTYPE']}"
>
> The code could be extended in the following ways:
>
> 1. more error checking (e.g. existence of test.csh)
> 2. handle variables with values that contain a newline
> 3. filter, e.g. include / exclude special variable names or by entries
> already present in the current environment.
>
> The last one is easy, just change one line
>
> ENV[$1] ||= $2
>
> Kind regards
>
> robert

Dear Robert,

Thanks for so detailed guide, many thanks.

By the way, is there something mis-writing? When I run the test.rb you 
gave, it reports error below, I'm still checking why?

test.rb:3:in `popen': can't convert Array into String (TypeError)

Best Regards,
Previn

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