[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

setting environment variables...

d c

11/24/2006 9:36:00 PM

hi -

i have a ruby command line script, and i want to set/export an
environment variable thats available to other various shell scripts
that are called by this ruby...

can someone tell me how to do this?

i thot this might work, but not...

ENV[' ENV['RSWF_C'] = 1 # use c bindings'] = 1


if i use (in ruby app:)
system(" RSWF_C=1; export RSWF_C" )

is this available to all other scripts called from this master ruby script?

thanks for any help, I'm a bit lost!

/dc
-------------------------------------------
David "DC" Collier
mailto:dc@pikkle.com
+81 (0)80 6521 9559
skype: callto://d3ntaku
-------------------------------------------
Pikkle ????
http://www....
-------------------------------------------

9 Answers

Paul Lutus

11/24/2006 11:00:00 PM

0

dc wrote:

> hi -
>
> i have a ruby command line script, and i want to set/export an
> environment variable thats available to other various shell scripts
> that are called by this ruby...

You can't do that. Each call to "system()" launches a new shell interpreter,
and they don't share environments.

>
> can someone tell me how to do this?

You cannot do this.

>
> i thot this might work, but not...
>
> ENV[' ENV['RSWF_C'] = 1 # use c bindings'] = 1
>
>
> if i use (in ruby app:)
> system(" RSWF_C=1; export RSWF_C" )
>
> is this available to all other scripts called from this master ruby
> script?

No.

Now, please tell us what problem you are trying to solve, rather than
evaluate this approach to solving it.

--
Paul Lutus
http://www.ara...

Ara.T.Howard

11/24/2006 11:14:00 PM

0

Paul Lutus

11/24/2006 11:24:00 PM

0

ara.t.howard@noaa.gov wrote:

/ ...

>> You cannot do this.
>
> why not?
>
> harp:~ > ruby -e' ENV["VAR"] = 42.to_s; system "env|grep VAR" '
> VAR=42
>
> the environment is definitely shared. did i mis-understand?

My reply was based on his diagrammed effort to use one system call to refer
to another system call:

>> if i use (in ruby app:)
>> system(" RSWF_C=1; export RSWF_C" )

>> is this available to all other scripts called from this
>> master ruby script?

The answer is obvious, and I provided it.

If instead his goal can be met by setting ENV variables within Ruby, then
that solves the problem. But before suggesting this, I asked that the OP
first explain what he is trying to do.

--
Paul Lutus
http://www.ara...

Ara.T.Howard

11/25/2006 12:19:00 AM

0

wmwilson01

11/25/2006 2:40:00 AM

0

Paul Lutus wrote:
> ara.t.howard@noaa.gov wrote:
>
> / ...
>
>>> You cannot do this.
>>
>> why not?
>>
>> harp:~ > ruby -e' ENV["VAR"] = 42.to_s; system "env|grep VAR" '
>> VAR=42
>>
>> the environment is definitely shared. did i mis-understand?
>
> My reply was based on his diagrammed effort to use one system call to
> refer
> to another system call:
>
>>> if i use (in ruby app:)
>>> system(" RSWF_C=1; export RSWF_C" )
>
>>> is this available to all other scripts called from this
>>> master ruby script?
>
> The answer is obvious, and I provided it.
>
> If instead his goal can be met by setting ENV variables within Ruby,
> then
> that solves the problem. But before suggesting this, I asked that the OP
> first explain what he is trying to do.


Gee, I thought it was quite obvious that he was trying to export a shell
variable. Was it not at least somewhat obvious to you? His first
paragraph was relatively straightforward about that. Anyways, my point
is that you probably could've just gone ahead and given him the answer
-- it would've added a mere 20 chars (max) to your post and been at
least 100 times more helpful. I dread the day when all of the Ruby hype
turns this community into the elitist/hostile environment that exists
for so many other languages.

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

x1

11/25/2006 2:56:00 AM

0

agreed.

Works on win32 also:

irb#1(main):011:0> ENV['time'] = Time.now.to_s and system('set|find "time"')
time=Fri Nov 24 21:55:23 -0500 2006
=> true

On 11/24/06, El Gato <wmwilson01@gmail.com> wrote:
> Paul Lutus wrote:
> > ara.t.howard@noaa.gov wrote:
> >
> > / ...
> >
> >>> You cannot do this.
> >>
> >> why not?
> >>
> >> harp:~ > ruby -e' ENV["VAR"] = 42.to_s; system "env|grep VAR" '
> >> VAR=42
> >>
> >> the environment is definitely shared. did i mis-understand?
> >
> > My reply was based on his diagrammed effort to use one system call to
> > refer
> > to another system call:
> >
> >>> if i use (in ruby app:)
> >>> system(" RSWF_C=1; export RSWF_C" )
> >
> >>> is this available to all other scripts called from this
> >>> master ruby script?
> >
> > The answer is obvious, and I provided it.
> >
> > If instead his goal can be met by setting ENV variables within Ruby,
> > then
> > that solves the problem. But before suggesting this, I asked that the OP
> > first explain what he is trying to do.
>
>
> Gee, I thought it was quite obvious that he was trying to export a shell
> variable. Was it not at least somewhat obvious to you? His first
> paragraph was relatively straightforward about that. Anyways, my point
> is that you probably could've just gone ahead and given him the answer
> -- it would've added a mere 20 chars (max) to your post and been at
> least 100 times more helpful. I dread the day when all of the Ruby hype
> turns this community into the elitist/hostile environment that exists
> for so many other languages.
>
> --
> Posted via http://www.ruby-....
>
>

d c

11/25/2006 4:28:00 AM

0

hi -

thanks for the help everyone.

> The answer is obvious, and I provided it.
indeed you did! you remind me of a very stoic colleague :)

the background is this:

we have a server written in ruby
when it starts up it looks for some environment variables for which
mode to run in (eg using custom c extensions, or just pure ruby)

I have a completely different ruby script (for benchmarking)

so, the benchmark script needs to communicate with the server, and the
way things are setup now, this would be via environment vars.

so,

bench.rb >> sets ENV['FLAG']
calls server.rb to start up (via a system() call currently)

server.rb >> on startup, looks for the FLAG env var and decides how to run.

I tried to do some research on what exactly ENV is, within ruby, but
didnt get much out of google...its a bit too common of a word.

if i just call system() to set an env flag,
then export it
will it then be available to other processes?

any more info on ENV would also be helpful
(or where to look - i find the ruby docs really awful)

> ri ENV
Nothing known about ENV


thanks for any help!


/dc


On 25/11/06, El Gato <wmwilson01@gmail.com> wrote:
> Paul Lutus wrote:
> > ara.t.howard@noaa.gov wrote:
> >
> > / ...
> >
> >>> You cannot do this.
> >>
> >> why not?
> >>
> >> harp:~ > ruby -e' ENV["VAR"] = 42.to_s; system "env|grep VAR" '
> >> VAR=42
> >>
> >> the environment is definitely shared. did i mis-understand?
> >
> > My reply was based on his diagrammed effort to use one system call to
> > refer
> > to another system call:
> >
> >>> if i use (in ruby app:)
> >>> system(" RSWF_C=1; export RSWF_C" )
> >
> >>> is this available to all other scripts called from this
> >>> master ruby script?
> >
> > The answer is obvious, and I provided it.
> >
> > If instead his goal can be met by setting ENV variables within Ruby,
> > then
> > that solves the problem. But before suggesting this, I asked that the OP
> > first explain what he is trying to do.
>
>
> Gee, I thought it was quite obvious that he was trying to export a shell
> variable. Was it not at least somewhat obvious to you? His first
> paragraph was relatively straightforward about that. Anyways, my point
> is that you probably could've just gone ahead and given him the answer
> -- it would've added a mere 20 chars (max) to your post and been at
> least 100 times more helpful. I dread the day when all of the Ruby hype
> turns this community into the elitist/hostile environment that exists
> for so many other languages.
>
> --
> Posted via http://www.ruby-....
>
>


--
-------------------------------------------
David "DC" Collier
mailto:dc@pikkle.com
+81 (0)80 6521 9559
skype: callto://d3ntaku
-------------------------------------------
Pikkle ????
http://www....
-------------------------------------------

Curt Sampson

11/25/2006 4:38:00 AM

0

Paul Lutus

11/25/2006 6:50:00 AM

0

ara.t.howard@noaa.gov wrote:

> On Sat, 25 Nov 2006, Paul Lutus wrote:
>
>>>> if i use (in ruby app:)
>>>> system(" RSWF_C=1; export RSWF_C" )
>>
>>>> is this available to all other scripts called from this
>>>> master ruby script?
>>
>> The answer is obvious, and I provided it.
>>
>> If instead his goal can be met by setting ENV variables within Ruby, then
>> that solves the problem. But before suggesting this, I asked that the OP
>> first explain what he is trying to do.
>
> then we are both right - the OP can solve his problem, but not the way he
> intended.

I agree that we are both right, but you are at least 10% more right than I
am. :)

I should have read his post more carefully -- I didn't spend enough time on
it.

--
Paul Lutus
http://www.ara...