[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

How to find Operating system

Newb Newb

4/8/2009 10:09:00 AM

Hi....
Here me looking for some help....
how to find web server's operating system ...

whether it is running under windows or linux...


Any helps

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

18 Answers

Robert Klemme

4/8/2009 10:47:00 AM

0

On 08.04.2009 12:09, Newb Newb wrote:
> Here me looking for some help....
> how to find web server's operating system ...

Do you mean remotely?

> whether it is running under windows or linux...

It depends what the server in question is willing to provide as
information. You can try to look at HTTP response header "Server" and
draw your conclusions (if it is IIS then the server must be some kind of
Windows).

Kind regards

robert

Ben Lovell

4/8/2009 10:54:00 AM

0

[Note: parts of this message were removed to make it a legal post.]

You can reach into the ENV object for a whole load of information about your
current execution environment:

ENV.to_hash.each do |key, value|
puts("#{key} - #{value}")
end


On Wed, Apr 8, 2009 at 11:09 AM, Newb Newb <revathy.p@angleritech.com>wrote:

> Hi....
> Here me looking for some help....
> how to find web server's operating system ...
>
> whether it is running under windows or linux...
>
>
> Any helps
>
> Thanks
> --
> Posted via http://www.ruby-....
>
>

Eleanor McHugh

4/8/2009 11:27:00 AM

0

On 8 Apr 2009, at 11:53, Ben Lovell wrote:
> You can reach into the ENV object for a whole load of information
> about your
> current execution environment:
>
> ENV.to_hash.each do |key, value|
> puts("#{key} - #{value}")
> end

Or you can use rbconfig:

require 'rbconfig'
case Config::CONFIG['host_os']
when /darwin/i
puts "Ah, Darwin :)"
when /mswin|windows/i
raise "You call that an operating system?"
else
raise "I haven't the foggiest"
end

However be aware that if you're using JRuby it will still report the
underlying OS which might not be as informative as you'd like so
you'll also need to check other CONFIG options.


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-...
----
raise ArgumentError unless @reality.responds_to? :reason



Mark S Bilk

4/8/2009 12:26:00 PM

0

On Apr 8, 4:27 am, Eleanor McHugh <elea...@games-with-brains.com>
wrote:
> Or you can use rbconfig:
>
>    require 'rbconfig'
>    case Config::CONFIG['host_os']
>    when /darwin/i
>      puts "Ah, Darwin :)"
>    when /mswin|windows/i
>      raise "You call that an operating system?"
>    else
>      raise "I haven't the foggiest"
>    end

Thanks, Eleanor! If I may suggest an additional clause
(with meaning in both the individual and group sense):

require 'rbconfig'
case Config::CONFIG['host_os']
when /darwin/i
puts "Ah, Darwin :)"
when /linux-gnu/i
puts "GNU/Linux - The World Community expands Consciousness"
when /mswin|windows/i
raise "You call that an operating system?"
else
raise "I haven't the foggiest"
end

Eleanor McHugh

4/8/2009 2:21:00 PM

0

On 8 Apr 2009, at 13:30, Mark S Bilk wrote:
> Thanks, Eleanor! If I may suggest an additional clause
> (with meaning in both the individual and group sense):
>
> require 'rbconfig'
> case Config::CONFIG['host_os']
> when /darwin/i
> puts "Ah, Darwin :)"
> when /linux-gnu/i
> puts "GNU/Linux - The World Community expands Consciousness"
> when /mswin|windows/i
> raise "You call that an operating system?"
> else
> raise "I haven't the foggiest"
> end

*grumble* *grumble* GPL *grumble* ;p


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-...
----
raise ArgumentError unless @reality.responds_to? :reason



James French

4/8/2009 2:29:00 PM

0

Hi,

Could anyone suggest an elegant way of doing something like:

$directXSDKBootstrapped =3D false

def bootstrapDirectXSDK
if !$directXSDKBootstrapped
bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}")
$directXSDKBootstrapped =3D true
$directXSDKBootstrapped.freeze
end
end

Obviously the intention is to only do something the first time it is called=
Maybe some little reusable util? I have a number of different bootstrap f=
unctions I want to apply this to.

Cheers,
James

Phlip

4/8/2009 2:35:00 PM

0

Don't think of them as "functions". Think of them as "methods", and always put
them inside classes.

James French wrote:
> Hi,
>
> Could anyone suggest an elegant way of doing something like:
>
> $directXSDKBootstrapped = false
>
> def bootstrapDirectXSDK
> if !$directXSDKBootstrapped
> bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}")
> $directXSDKBootstrapped = true
> $directXSDKBootstrapped.freeze
> end
> end

class Whatever
def bootstrapDirectXSDK
@@directXSDKBootstrapped ||=
bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}")
end
end

That's teh "proxy pattern" in Ruby...

LAMBEAU Bernard

4/8/2009 2:41:00 PM

0

One way to do it, which requires a good understanding of
metaprogramming, could be as follows:

class Class

# Replaces the method whose name is provided by a
# method that calls the original one the first time it is called
# and by a noop method for subsequent calls.
def one_call_only(method_name)
# implement me
end

end

class MyClass
def bootstrapDirectXSDK
bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}")
end
one_call_only :bootstrapDirectXSDK
end

I'm not sure it's the simplest way to do it. I can sketch the actual
code of one_call_only if it helps.

blambeau

On Wed, Apr 8, 2009 at 4:29 PM, James French
<James.French@naturalmotion.com> wrote:
> Hi,
>
> Could anyone suggest an elegant way of doing something like:
>
> $directXSDKBootstrapped =3D false
>
> def bootstrapDirectXSDK
> =A0if !$directXSDKBootstrapped
> =A0 =A0bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}")
> =A0 =A0$directXSDKBootstrapped =3D true
> =A0 =A0$directXSDKBootstrapped.freeze
> =A0end
> end
>
> Obviously the intention is to only do something the first time it is call=
ed. Maybe some little reusable util? I have a number of different bootstrap=
functions I want to apply this to.
>
> Cheers,
> James
>
>

James Coglan

4/8/2009 2:43:00 PM

0

[Note: parts of this message were removed to make it a legal post.]

> Could anyone suggest an elegant way of doing something like:
>
> $directXSDKBootstrapped = false
>
> def bootstrapDirectXSDK
> if !$directXSDKBootstrapped
> bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}")
> $directXSDKBootstrapped = true
> $directXSDKBootstrapped.freeze
> end
> end



One way of doing this is as follows:

class Proc
def runs(n)
wrapped, count = self, 0
lambda { |*args|
count += 1
count <= n ? wrapped.call(*args) : nil
}
end
end

>> foo = lambda { |arg| puts arg }.runs(3)
#=> #<Proc:0xb7d310dc@(irb):33>

>> foo['look!']
look!
=> nil
>> foo['look!']
look!
=> nil
>> foo['look!']
look!
=> nil
>> foo['look!']
=> nil

Notice nothing is printed the fourth time. So using this, you could write
you function as:

bootstrapDirectXSDK = lambda {
bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}")
}.runs(1)

Which will only allow its contents to be executed once.

--
James Coglan
http://github.c...

Henrik Hodne

4/8/2009 2:46:00 PM

0

Look in the response headers, the server software should be there (and
often the OS)

Regards,
Henrik Hodne

On 8 Apr 2009, at 12:09, Newb Newb <revathy.p@angleritech.com> wrote:

> Hi....
> Here me looking for some help....
> how to find web server's operating system ...
>
> whether it is running under windows or linux...
>
>
> Any helps
>
> Thanks
> --
> Posted via http://www.ruby-....
>