[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

how to temporaly change enviroment variable

Roman Dolgov

7/15/2003 8:17:00 PM

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.


thank you
Roman



__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc...

2 Answers

Jason Creighton

7/16/2003 4:57:00 AM

0

On Wed, 16 Jul 2003 05:17:11 +0900
Roman Dolgov <roman_dolgov@yahoo.com> 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.

ENV["PATH"] = "/new/path"

Jason Creighton

robert ehteshamzadeh

7/16/2003 5:47:00 AM

0

When you run a ruby script, ruby is a child process of your shell.
On Windows it looks like this:

explorer.exe
cmd.exe (shell)
ruby.exe

each exe has it''s own environment. It inherits the environment of it''s
parent, and can
change it''s own environment but not it''s parent''s env.

so you can change the shell''s environment with a shell script ( or batch
file )
and you can change the environment of a script while it''s running by
puts ENV["PATH"] # shows "/old/path"
ENV["PATH"] = "/new/path"
puts ENV["PATH"] # shows "/new/path"

but if you echo the env var after the script has finished, you will still
see the old path.

If you wish to change the environment of the shell, you must do it with a
shell script (batch file).

"Jason Creighton" <androflux@softhome.net.remove.to.reply> wrote in message
news:20030715225659.443b6445.androflux@softhome.net.remove.to.reply...
> On Wed, 16 Jul 2003 05:17:11 +0900
> Roman Dolgov <roman_dolgov@yahoo.com> 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.
>
> ENV["PATH"] = "/new/path"
>
> Jason Creighton
>