Foolproof way of determining host platform

P

Paul Mckibbin

Hi all,

I am trying to work out a 'better' way of determing if my ruby code is
running on a Windows platform, and so far I've had to modify the
standard RUBY_PLATFORM several times depending on which version of
windows/compiler etc. it was built with. I also tried using

require 'rbconfig'
Config::CONFIG['host_os']

but found that (with 1.8.6) there are still distinction versions
reported on windows, such as a mingw32 build reporting an os of
'mingw32'.

I came up with Config::CONFIG['EXEEXT'] to determine whether it is
running on Windows as opposed to any other platform we support. Windows
return ".exe" and other platforms tested come back with "", so that
seems to work, but is there a better way?

Best wishes,
Mac
 
P

Phillip Gawlowski

I came up with Config::CONFIG['EXEEXT'] to determine whether it is
running on Windows as opposed to any other platform we support. Windows
return ".exe" and other platforms tested come back with "", so that
seems to work, but is there a better way?

You can give a binary any extension you like on *NIX, as long as you set
"chmod +x /my/binary.whatever".
 
L

Luis Lavena

Hi all,

I am trying to work out a 'better' way of determing if my ruby code is
running on a Windows platform, and so far I've had to modify the
standard RUBY_PLATFORM several times depending on which version of
windows/compiler etc. it was built with. I also tried using

require 'rbconfig'
Config::CONFIG['host_os']

but found that (with 1.8.6) there are still distinction versions
reported on windows, such as a mingw32 build reporting an os of
'mingw32'.

That is because is not the OS, but also the C Runtime used to link to
Ruby and the tools to built it.

MinGW == GCC and mswin32 for VC6

Also mswin32_80 for VS2008

And you also have cygwin and other compilers.
I came up with Config::CONFIG['EXEEXT'] to determine whether it is
running on Windows as opposed to any other platform we support. Windows
return ".exe" and other platforms tested come back with "", so that
seems to work, but is there a better way?

host_os and evaluate /mswin|mingw/

There is no perfect solution.
 
I

Intransition

Other options:

require 'rubygems'
Gem::platform.local

Shameless ripoff with some minor improvements:

require 'facets/platform'
Platform.local

The OS gem looks promising.

My question is why isn't something like this a standard part of Ruby?
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top