On Tuesday, July 15, 2003, at 04:17 PM, Roman Dolgov wrote:

> Hi All,
>
> Is there any way to change enviroment variable during
> execution of ruby script inside of the script.
>
> (for ex PATH )
>
> So when I use `` command
>
> # change PATH somehow
> `run.exe`
>
> run.exe will be picked up from the modified PATH.
> [snip]

I recommend that you take a look at 'shell.rb', which is part of the 
standard distribution. It seems that you may be using Windows 
(run.exe), which I have not tested the below on, but I have heard that 
shell.rb generally works the same on Windows as on a Unix-based OS.

require 'shell'
Shell.def_system_command("command")
Shell.def_system_command("command2")
shell = Shell.cd("directory")
shell.transact do
   shell.command([args])
   shell.command2([args])
end

One of the commands could set an environment variable and another could 
run a command line program. For example, 'shell.env' lists all 
environment variables and 'shell.env("LINES=42")' will set the LINES 
variable to the value 42.

The class method 'def_system_command' adds the command given as an 
argument as an instance method of all Shell objects. 'Shell.cd' creates 
a Shell object in the directory given as an argument. 'shell.transact 
do . . . end' takes advantage of process control functionality built 
into the Shell class.

Regards,

Mark