Forum: Ruby How Ruby environment varibles work in realtime program?

Posted by Love U Ruby (my-ruby)
on 2013-01-11 13:41
Hi,

I just introduced myself to the below the environment variables:

DLN_LIBRARY_PATH,HOME,LOGDIR,RUBYOPT,RUBYSHELL

Now m question is does these variables keep with them any constant value
or the values are loaded on run time?

Can you give me a small snippet by which I can understand each of the
environment variable how works in real-time application?


Anyway to show the values of those variables if they are containing
static values?

Thanks
Posted by Robert Klemme (robert_k78)
on 2013-01-11 14:08
(Received via mailing list)
On Fri, Jan 11, 2013 at 1:41 PM, Arup Rakshit <lists@ruby-forum.com> 
wrote:
> Now m question is does these variables keep with them any constant value
> or the values are loaded on run time?

I am not sure I understand what you are asking. The Ruby interpreter,
like any other process, inherits environment variables from the
calling process.  If it changes values of those variables those
changes are again inherited by processes started by the interpreter.

> Can you give me a small snippet by which I can understand each of the
> environment variable how works in real-time application?

What do environment variables have to do with realtime applications?
I don't see any specific different handling of environment variables
in realtime and non realtime applications.

> Anyway to show the values of those variables if they are containing
> static values?

What do you mean by "static"?  Since they are variables their values
can change - any time.

Kind regards

robert
Posted by Love U Ruby (my-ruby)
on 2013-01-11 14:34
Robert Klemme wrote in post #1091908:
> On Fri, Jan 11, 2013 at 1:41 PM, Arup Rakshit <lists@ruby-forum.com>
> wrote:
>> Now m question is does these variables keep with them any constant value
>> Anyway to show the values of those variables if they are containing
>> static values?
>
> What do you mean by "static"?  Since they are variables their values
> can change - any time.
>
> Kind regards
>
> robert


`static` value means i tried to say if those variables having values at 
the time Ruby installations. But now is there any way to check what the 
values of such variables containing at any point of time. Any specific 
command.

Note: I am using Windows - 7

Thanks
Posted by Joel Pearson (virtuoso)
on 2013-01-11 14:50
I should think
[DLN_LIBRARY_PATH, HOME, LOGDIR, RUBYOPT, RUBYSHELL].each {|var| puts 
var }
would suffice to check them all whenever you want.
Posted by Love U Ruby (my-ruby)
on 2013-01-11 15:13
Joel Pearson wrote in post #1091923:
> I should think
> [DLN_LIBRARY_PATH, HOME, LOGDIR, RUBYOPT, RUBYSHELL].each {|var| puts
> var }
> would suffice to check them all whenever you want.

I am getting the below error:


Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\rakshit>irb
irb(main):001:0> [DIN_LIBRARY_PATH,HOME,LOGDIR,RUBYOPT,RUBYSHELL].each 
{|var|put
s var }
NameError: uninitialized constant DIN_LIBRARY_PATH
        from (irb):1
irb(main):002:0> [DLN_LIBRARY_PATH,HOME,LOGDIR,RUBYOPT,RUBYSHELL].each 
{|var|put
s var }
NameError: uninitialized constant DLN_LIBRARY_PATH
        from (irb):2
irb(main):003:0>                  ^C
irb(main):003:0> exit
Terminate batch job (Y/N)? y

C:\Documents and Settings\rakshiar>
Posted by Joel Pearson (virtuoso)
on 2013-01-11 15:53
Oops, forgot the dollar signs. FYI that's a single line of code, it gets 
put onto 2 lines by a line character limit on the forum.

[$DLN_LIBRARY_PATH, $HOME, $LOGDIR, $RUBYOPT, $RUBYSHELL].each {|var| 
puts var }

When I run that in IRB they all come out as nil, presumably because in 
that environment they aren't set.
Posted by Jeremy Bopp (Guest)
on 2013-01-11 16:02
(Received via mailing list)
On 01/11/2013 08:14 AM, Arup Rakshit wrote:
> (C) Copyright 1985-2001 Microsoft Corp.
> NameError: uninitialized constant DLN_LIBRARY_PATH
>         from (irb):2

As you can see, Ruby thinks those names you specified are constants, but
you need them to be strings in this case.  You also need to look up
their values via the ENV hash:

%w(DIN_LIBRARY_PATH HOME LOGDIR RUBYOPT RUBYSHELL).each do |var|
  puts "#{var}=#{ENV[var]}"
end

The %w above takes a string defined between the parenthesis and splits
it on whitespace.  The result is an array of strings that we then
iterate over.  Then we print the variable name and the value of that
variable from the environment via the ENV hash.

-Jeremy
Posted by Jeremy Bopp (Guest)
on 2013-01-11 16:03
(Received via mailing list)
On 01/11/2013 08:54 AM, Joel Pearson wrote:
> Oops, forgot the dollar signs. FYI that's a single line of code, it gets
> put onto 2 lines by a line character limit on the forum.
>
> [$DLN_LIBRARY_PATH, $HOME, $LOGDIR, $RUBYOPT, $RUBYSHELL].each {|var|
> puts var }
>
> When I run that in IRB they all come out as nil, presumably because in
> that environment they aren't set.

You're in Ruby here, not bash, so those names are global variable
references for variables that haven't been defined.  Therefore they
default to nil.  See my earlier reply for what you really intended to
do. :-)

-Jeremy
Posted by Robert Klemme (robert_k78)
on 2013-01-11 16:03
(Received via mailing list)
On Fri, Jan 11, 2013 at 3:54 PM, Joel Pearson <lists@ruby-forum.com> 
wrote:
> Oops, forgot the dollar signs. FYI that's a single line of code, it gets
> put onto 2 lines by a line character limit on the forum.
>
> [$DLN_LIBRARY_PATH, $HOME, $LOGDIR, $RUBYOPT, $RUBYSHELL].each {|var|
> puts var }
>
> When I run that in IRB they all come out as nil, presumably because in
> that environment they aren't set.

These are global variables and not environment variables!  Please see
Jeremy's reply for how to access environment variables.

Kind regards

robert
Posted by Love U Ruby (my-ruby)
on 2013-01-11 16:05
Joel Pearson wrote in post #1091935:
> Oops, forgot the dollar signs. FYI that's a single line of code, it gets
> put onto 2 lines by a line character limit on the forum.
>

What the reason could be of not to set the variables? and how should I 
need
to set such variables?

Too much confused! :(
Posted by Joel Pearson (virtuoso)
on 2013-01-11 16:45
Jeremy's answer is right, I got confused about what variables you were 
looking at.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.