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.
Regards,
Afaque
···
---------------------------------
Yahoo! Mail Mobile
Take Yahoo! Mail with you! Check email on your mobile phone.
Simply put, you can't do this. #exec and #system start new copies of
the command interpreter (cmd.exe) and the environment variables are
set in that environment, which is subordinate to the Ruby
interpreter process.
You'd be better off parsing the BAT file for SET commands. And using ENV.
-austin
···
On 5/26/05, Afaque Ahmad <ahmads_786@yahoo.com> wrote:
I am having problems setting and reading enviroment variables from
a windows batch file.
--
Austin Ziegler * halostatue@gmail.com
* Alternate: austin@halostatue.ca
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
···
On 26/05/05, Afaque Ahmad <ahmads_786@yahoo.com> 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.
--
http://ruby.brian-schroeder.de/
Stringed instrument chords: http://chordlist.brian-schroeder.de/