[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

detect operating system?

Steve L

5/16/2006 5:29:00 AM

Hello,

What is the easiest way to detect what operating system your running in
a ruby script? I have a script that needs to run on several versions of
linux and on windows. The code executed is different depending on which
machine I'm on. What is the best way to do this?

Janak


8 Answers

Dmitry Buzdin

5/16/2006 6:37:00 AM

0

require "rbconfig"
include Config
puts CONFIG["host"]

sabat

5/16/2006 4:18:00 PM

0

Check the environment variables.

If ENV['OS'] == "Windows_NT" then you know where you are. If ENV['OS']
is empty then you're on linux. (There are some other signs if you want
to know for sure you're on linux/unix -- for instance, ENV['USER'] will
be set to the username. On Windows, it's ENV['USERNAME'] instead.

Ross Bamford

5/16/2006 4:22:00 PM

0

On Tue, 16 May 2006 06:29:09 +0100, J <a@b.c> wrote:

> Hello,
>
> What is the easiest way to detect what operating system your running
> in a ruby script?

Does the RUBY_PLATFORM const provide the needed info?

$ irb
RUBY_PLATFORM
# => "i686-linux"

--
Ross Bamford - rosco@roscopeco.remove.co.uk

crumbs.j

5/16/2006 6:06:00 PM

0

this works for me
C:\ruby>bin\ruby src\test.rb
i386-mswin32

I am extremelly new to ruby as well. [ Today is the FIRST day I have
ever looked into it ] I come from a Perl and now Java background

Does anyone have any pdf/docs to get a guy started?

-CB
http://www.i...

slunky

5/16/2006 6:07:00 PM

0

_/ crumbs.j@gmail.com wrote \_
> Does anyone have any pdf/docs to get a guy started?

alt.binaries.e-book.technical has a few.

--
-slunky

Daniel Berger

5/16/2006 6:54:00 PM

0

J wrote:
> Hello,
>
> What is the easiest way to detect what operating system your running in
> a ruby script? I have a script that needs to run on several versions of
> linux and on windows. The code executed is different depending on which
> machine I'm on. What is the best way to do this?
>
> Janak

Use RUBY_PLATFORM for a simple platform string.

If you need more advanced information, take a look at sys-uname,
available on the RAA.

Regards,

Dan

Tim Hunter

5/16/2006 8:03:00 PM

0

crumbs.j@gmail.com wrote:
> this works for me
> C:\ruby>bin\ruby src\test.rb
> i386-mswin32
>
> I am extremelly new to ruby as well. [ Today is the FIRST day I have
> ever looked into it ] I come from a Perl and now Java background
>
> Does anyone have any pdf/docs to get a guy started?
>
> -CB
> http://www.i...
>

www.ruby-doc.org

sabat

5/18/2006 2:43:00 AM

0

You'll find Ruby to be similar in ways to Perl and to Java. (The
similarities include all the good stuff, and pretty much none of the
annoyances and other problems of those languages.)

Most people like the 'Pickaxe book' whose title is actually Programming
Ruby. It's in its second edition now, which you have to buy (pdf or
hard copy), but the first edition is perfectly fine for your purposes,
and it's free at the url below. The pickaxe book is both a tutorial
(first part) and a reference (the second part).

http://www.rubycentral...