Foolproof way of determining host platform

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

On 15.01.2010 21:21, Paul M. wrote:

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

On Jan 15, 5:21 pm, Paul M. [email protected] wrote:

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.

Paul M. wrote:

Hi all,

I am trying to work out a ‘better’ way of determing if my ruby code is
running on a Windows platform […]

http://www.ruby-forum.com/topic/202166

Man, one gem gets released and tons of people suddenly have a need for
it.

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?

Thomas S. wrote:

The OS gem looks promising.

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

One word: Skynet.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs