[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Easiest way to determine OS?

Wes Gamble

10/30/2006 9:14:00 PM

What's the easiest way to figure out if you are on a Windows vs. UNIX
platform in Ruby from within a Ruby program?

Thanks,
Wes

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

3 Answers

Brad Tilley

10/30/2006 9:25:00 PM

0

Wes Gamble wrote:
> What's the easiest way to figure out if you are on a Windows vs. UNIX
> platform in Ruby from within a Ruby program?

Try this:

irb(main):005:0> puts RUBY_PLATFORM
powerpc-darwin8.0



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

Victor 'Zverok' Shepelev

10/30/2006 9:42:00 PM

0

From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf Of
Brad Tilley
Sent: Monday, October 30, 2006 11:25 PM
>Wes Gamble wrote:
>> What's the easiest way to figure out if you are on a Windows vs. UNIX
>> platform in Ruby from within a Ruby program?
>
>Try this:
>
>irb(main):005:0> puts RUBY_PLATFORM
>powerpc-darwin8.0
>

Not very useful sometimes:

irb(main):001:0> puts RUBY_PLATFORM
i386-mswin32_71
(1) (2) (3)(4)

Here's encoded: CPU architecture (1), OS (2), CPU bits (3), compiler (4 -
it's MS Visual Studio 7.1)

Pasing this on every platform may become a pain.

v.


Jeremy Hinegardner

10/31/2006 5:23:00 AM

0

On Tue, Oct 31, 2006 at 06:41:53AM +0900, Victor Zverok Shepelev wrote:
> From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf Of
> Brad Tilley
> Sent: Monday, October 30, 2006 11:25 PM
> >Wes Gamble wrote:
> >> What's the easiest way to figure out if you are on a Windows vs. UNIX
> >> platform in Ruby from within a Ruby program?

RUBY_PLATFORM is pretty good, but don't forget about the 'rbconfig'
module either.

puts RUBY_PLATFORM # => 'i386-linux'

require 'rbconfig'
puts Config::CONFIG['target_cpu'] # => 'i386'
puts Config::CONFIG['target_os'] # => 'linux'
puts Config::CONFIG['host_cpu'] # => 'i686'
puts Config::CONFIG['host_os'] # => 'linux-gnu'

good stuff there.

> >Try this:
> >
> >irb(main):005:0> puts RUBY_PLATFORM
> >powerpc-darwin8.0
> >
>
> Not very useful sometimes:
>
> irb(main):001:0> puts RUBY_PLATFORM
> i386-mswin32_71
> (1) (2) (3)(4)
>
> Here's encoded: CPU architecture (1), OS (2), CPU bits (3), compiler (4 -
> it's MS Visual Studio 7.1)
>
> Pasing this on every platform may become a pain.

Plug around in the 'rbconfig' module, see if any of the items in there
work better.

enjoy,

-jeremy

--
========================================================================
Jeremy Hinegardner jeremy@hinegardner.org