# Foolproof way of determining host platform

**URL:** <https://www.ruby-forum.com/t/foolproof-way-of-determining-host-platform/181676>\
**Category:** Ruby\
**Created:** [January 15, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/foolproof-way-of-determining-host-platform/181676 "2010-01-15T21:21:31Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![paul-au](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@paul-au](https://www.ruby-forum.com/u/paul-au)\
**Post date:** [January 15, 2010, 9:21pm UTC](https://www.ruby-forum.com/t/foolproof-way-of-determining-host-platform/181676/1 "2010-01-15T21:21:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-au](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@paul-au](https://www.ruby-forum.com/u/paul-au)\
**Post date:** [January 15, 2010, 9:39pm UTC](https://www.ruby-forum.com/t/foolproof-way-of-determining-host-platform/181676/2 "2010-01-15T21:39:09Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![paul-au](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@paul-au](https://www.ruby-forum.com/u/paul-au)\
**Post date:** [January 15, 2010, 9:50pm UTC](https://www.ruby-forum.com/t/foolproof-way-of-determining-host-platform/181676/3 "2010-01-15T21:50:51Z")

</div>

On Jan 15, 5:21 pm, Paul M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

---

<div class="post-metadata">

**Author:** ![paul-au](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@paul-au](https://www.ruby-forum.com/u/paul-au)\
**Post date:** [January 15, 2010, 9:51pm UTC](https://www.ruby-forum.com/t/foolproof-way-of-determining-host-platform/181676/4 "2010-01-15T21:51:47Z")

</div>

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](http://www.ruby-forum.com/topic/202166)

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

---

<div class="post-metadata">

**Author:** ![paul-au](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@paul-au](https://www.ruby-forum.com/u/paul-au)\
**Post date:** [January 16, 2010, 12:25am UTC](https://www.ruby-forum.com/t/foolproof-way-of-determining-host-platform/181676/5 "2010-01-16T00:25:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![paul-au](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/f475e1/32.png) [@paul-au](https://www.ruby-forum.com/u/paul-au)\
**Post date:** [January 16, 2010, 12:53am UTC](https://www.ruby-forum.com/t/foolproof-way-of-determining-host-platform/181676/6 "2010-01-16T00:53:28Z")

</div>

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.
