How to find Operating system

N

Newb Newb

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
 
R

Robert Klemme

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
 
B

Ben Lovell

[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
 
E

Eleanor McHugh

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-brains.net
 
M

Mark S Bilk

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
 
E

Eleanor McHugh

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-brains.net
 
J

James French

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
 
P

Phlip

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

James said:
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...
 
L

LAMBEAU Bernard

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

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.
 
J

James Coglan

[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)
#=> # said:
foo['look!']
look!
=> nil
look!
=> nil
look!
=> nil
=> 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.
 
H

Henrik Hodne

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

Regards,
Henrik Hodne
 
J

James French

I see I still have some way to go with ruby :) Nice! Can't believe how quic=
k you knocked that up...

-----Original Message-----
From: James Coglan [mailto:[email protected]]=20
Sent: 08 April 2009 15:43
To: ruby-talk ML
Subject: Re: performing an action only the first time a function called
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



One way of doing this is as follows:

class Proc
def runs(n)
wrapped, count =3D self, 0
lambda { |*args|
count +=3D 1
count <=3D n ? wrapped.call(*args) : nil
}
end
end
foo =3D lambda { |arg| puts arg }.runs(3)
#=3D> # said:
foo['look!']
look!
=3D> nil
look!
=3D> nil
look!
=3D> nil
=3D> nil

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

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

Which will only allow its contents to be executed once.
 
J

James French

I have to admit though, I don't understand the 'wrapped, count =3D self, 0'=
line...

-----Original Message-----
From: James French [mailto:[email protected]]=20
Sent: 08 April 2009 16:13
To: ruby-talk ML
Subject: Re: performing an action only the first time a function called

I see I still have some way to go with ruby :) Nice! Can't believe how quic=
k you knocked that up...

-----Original Message-----
From: James Coglan [mailto:[email protected]]=20
Sent: 08 April 2009 15:43
To: ruby-talk ML
Subject: Re: performing an action only the first time a function called
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



One way of doing this is as follows:

class Proc
def runs(n)
wrapped, count =3D self, 0
lambda { |*args|
count +=3D 1
count <=3D n ? wrapped.call(*args) : nil
}
end
end
foo =3D lambda { |arg| puts arg }.runs(3)
#=3D> # said:
foo['look!']
look!
=3D> nil
look!
=3D> nil
look!
=3D> nil
=3D> nil

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

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

Which will only allow its contents to be executed once.
 
L

Leo

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

You could redefine bootstrapDirectXSDK:

$directXSDKBootstrapped =3D false

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

James Coglan

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

2009/4/8 James French said:
I have to admit though, I don't understand the 'wrapped, count = self, 0'
line...


That's just parallel assignment, it's equivalent to:

wrapped = self
count = 0
 
J

James French

Ahh, thanks.

-----Original Message-----
From: James Coglan [mailto:[email protected]]=20
Sent: 08 April 2009 16:45
To: ruby-talk ML
Subject: Re: performing an action only the first time a function called

2009/4/8 James French said:
I have to admit though, I don't understand the 'wrapped, count =3D self, = 0'
line...


That's just parallel assignment, it's equivalent to:

wrapped =3D self
count =3D 0
 
J

James French

I like it, but you get a warning with -w...

-----Original Message-----
From: Leo [mailto:[email protected]]=20
Sent: 08 April 2009 16:43
To: ruby-talk ML
Subject: Re: performing an action only the first time a function called
$directXSDKBootstrapped =3D false

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

You could redefine bootstrapDirectXSDK:

$directXSDKBootstrapped =3D false

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

Robert Klemme

On 08.04.2009 16:29, James French wrote:

Please do not hijack other threads.
Could anyone suggest an elegant way of doing something like:

$directXSDKBootstrapped = false

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

Freezing has no effect here because it does not prevent reassignment to
the variable.
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 functions I want to apply this to.

Why can't you just invoke the initialization once and be done? If this
is in a file which is required then Ruby will take care of this
automatically.

Another solution:

class OnlyOnce
def initialize(&b)
raise "Need a block!" unless b
@block = b
end

def get
if @block
@val = block.call
@block = nil
end

@val
end
end

$directXSDKBootstrapped = OnlyOnce.new do
bootstrapBuildToolsDirectory("DirectX/#{DIRECTX_VERSION}")
end

Cheers

robert
 
B

botp

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 functions I want to apply this to.

sometimes, i apply ruby's nested methods feature...

eg,

botp@jedi-hopeful:~$ cat test.rb
def only_once_dumper
def only_once
end
end

def only_once
puts "i ran once!"
only_once_dumper
end

only_once
only_once
only_once

botp@jedi-hopeful:~$ ruby test.rb
i ran once!
botp@jedi-hopeful:~$

kind regards -botp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top