From: "Brian Schröder" Date: 2005-05-26T21:36:17+09:00 Subject: Re: setting environment variables using windows batch file On 26/05/05, Afaque Ahmad wrote: > Dear Ruby Members, > > I am having problems setting and reading enviroment variables from a windows batch file. > > This is what I am doing, I have some batch file xyz.bat where I am setting some enviroment > variable > > SET ENV_VAR1 = "something" > SET ENV_VAR2 = "foo" > > I wish to run the batch file from ruby script , wherein which I can use these environment variables within the ruby file itself. I use the following command to run the batch file > > system("xyz.bat") > > But even after doing this , the environment variables ENV_VAR1 and ENV_VAR2 don't get set. > I even tried using > exec("xyz.bat") > system("cmd /k xyz.bat") > > I would really appreciate it if anybody could tell me what I am doing wrong here. > Hello Afaque, it should be possible if you can invert your problem. If you start the ruby interpreter from the batch file, you have the variables set. --8<---test.bat---8<--- SET FOO = "foo" ruby test.rb --8<-----------------8<-- --8<---test.rb---8<--- puts ENV['FOO'] --8<-----------------8<-- If you want to use the batch file as some kind of configuration file, maybe you could revert to a real configuration file. E.g. in yaml. best regards, Brian Schr�der -- http://ruby.brian-schroeder.de/ Stringed instrument chords: http://chordlist.brian-schroeder.de/