# [Ironruby-core] The Proper way to detect the Windows Platform in Ruby

Will Green will at hotgazpacho.org
Thu Mar 11 17:01:57 EST 2010

```Yikes!

Well, those are all OSS projects. We should fork them, fix them, and send
pull requests/patches ;-)

--
Will Green
http://hotgazpacho.org/

On Thu, Mar 11, 2010 at 4:39 PM, Tomas Matousek <
Tomas.Matousek at microsoft.com> wrote:

>  Sure, using RUBY_PLATFORM is not good. However if you search thru Ruby
> gems it's used all over the place :(
> So until at least 90% of Ruby apps detect OS specific features properly we
> need to keep RUBY_PLATFORM set to win32/darwin/linux depending on the
> underlying OS. I guess some gems might be broken on JRuby on Windows since
> they don't check for "java".
>
>   ruby-1.8.6p368\lib\ruby\1.8\ftools.rb(103):    if RUBY_PLATFORM =~
> /djgpp|(cyg|ms|bcc)win|mingw/ and file? to
>   ruby-1.8.6p368\lib\ruby\1.8\drb\extservm.rb(89):      if RUBY_PLATFORM =~
> /mswin32/ && /NT/ =~ ENV["OS"]
>   ruby-1.8.6p368\lib\ruby\1.8\rdoc\options.rb(547):    return if
> RUBY_PLATFORM =~ /win/
>   ruby-1.8.6p368\lib\ruby\1.8\soap\streamHandler.rb(23):
> RUBY_VERSION_STRING = "ruby #{ RUBY_VERSION } (#{ RUBY_RELEASE_DATE }) [#{
> RUBY_PLATFORM }]"
>   ruby-1.8.6p368\lib\ruby\1.8\xmlrpc\server.rb(643):    if RUBY_PLATFORM =~
> /mingw|mswin32/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\actionpack-2.3.5\test\controller\layout_test.rb(201):unless
> RUBY_PLATFORM =~ /(:?mswin|mingw|bccwin)/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\activesupport-2.3.5\lib\active_support\core_ext\kernel\reporting.rb(38):
> stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\activesupport-2.3.5\lib\active_support\xml_mini\jdom.rb(1):raise
> "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM
> =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\activesupport-3.0.pre\lib\active_support\core_ext\kernel\reporting.rb(40):
> stream.reopen(RUBY_PLATFORM =~ /mswin/ ? 'NUL:' : '/dev/null')
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\activesupport-3.0.pre\lib\active_support\testing\isolation.rb(36):
> !ENV["NO_FORK"] && RUBY_PLATFORM !~ /mswin|mingw|java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\activesupport-3.0.pre\lib\active_support\xml_mini\jdom.rb(1):raise
> "JRuby is required to use the JDOM backend for XmlMini" unless RUBY_PLATFORM
> =~ /java/
>
> = (RUBY_PLATFORM != "java" && RUBY_VERSION =~ /^1\.8/)
>
> = (RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/) rescue false
>
> if RUBY_PLATFORM =~ /mswin/
>
> if RUBY_PLATFORM =~ /mswin/
>
> = (RUBY_PLATFORM != "java" && RUBY_VERSION =~ /^1\.8/)
>
> = (RUBY_PLATFORM =~ /mswin|win32|mingw|bccwin|cygwin/) rescue false
>
> if RUBY_PLATFORM =~ /mswin/
>
> if RUBY_PLATFORM =~ /mswin/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\cgi_multipart_eof_fix-2.5.0\lib\cgi_multipart_eof_fix.rb(8):if
> version [0] < 2 and version [1] < 9 and version [2] < 6 and RUBY_PLATFORM !~
> /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\cgi_multipart_eof_fix-2.5.0\test\test_cgi_multipart_eof_fix.rb(18):IS_VULNERABLE
> = (version [0] < 2 and version [1] < 9 and version [2] < 6 and RUBY_PLATFORM
> !~ /java/)
>
> RUBY_APP = if RUBY_PLATFORM =~ /java/
>
> RUBY_APP = if RUBY_PLATFORM =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\data_objects-0.9.12\Rakefile(9):JRUBY
> = RUBY_PLATFORM =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\data_objects-0.9.12\lib\data_objects\connection.rb(19):
> warn 'JNDI URLs (connection strings) are only for use with JRuby' unless
> RUBY_PLATFORM =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\data_objects-0.9.12\lib\data_objects\connection.rb(22):
> warn 'JDBC URLs (connection strings) are only for use with JRuby' unless
> RUBY_PLATFORM =~ /java/
>
> RUBY_PLATFORM =~ /java/
>
> = (RUBY_PLATFORM =~ /win32|mingw|bccwin|cygwin/) rescue nil
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\dm-serializer-0.9.11\Rakefile(5):JRUBY
> = RUBY_PLATFORM =~ /java/
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\dm-types-0.9.11\Rakefile(5):JRUBY
> = RUBY_PLATFORM =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\dm-validations-0.9.11\Rakefile(5):JRUBY
> = RUBY_PLATFORM =~ /java/
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\extlib-0.9.12\Rakefile(13):JRUBY
> = RUBY_PLATFORM =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\extlib-0.9.12\spec\pooling_spec.rb(61):
> pool_size = if RUBY_PLATFORM =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\gem_plugin-0.2.3\resources\Rakefile(35):
> p.need_tar = true if RUBY_PLATFORM !~ /mswin/
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\haml-2.2.2\Rakefile(67):  sudo =
> RUBY_PLATFORM =~ /win32/ ? '' : 'sudo'
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\haml-2.2.2\Rakefile(68):  gem  =
> RUBY_PLATFORM =~ /java/  ? 'jgem' : 'gem'
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\highline-1.5.1\lib\highline\system_extensions.rb(21):
> raise LoadError, "Cygwin is a Posix OS." if RUBY_PLATFORM =~ /\bcygwin\b/i
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\highline-1.5.1\lib\highline\system_extensions.rb(184):
> if /solaris/ =~ RUBY_PLATFORM and
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\hoe-2.3.3\lib\hoe.rb(91):  WINDOZE
> = /mswin|mingw/ =~ RUBY_PLATFORM unless defined? WINDOZE
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\merb-action-args-1.0.12\lib\merb-action-args\get_args.rb(1):unless
> RUBY_PLATFORM == "java"
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\merb-core-1.0.12\Rakefile(408):
> spec_cmd = (RUBY_PLATFORM =~ /java/) ? "jruby -S spec" : "spec"
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\merb-core-1.0.12\lib\merb-core.rb(778):
> RUBY_PLATFORM =~ Merb::Const::JAVA_PLATFORM_REGEXP
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\merb-core-1.0.12\lib\merb-core.rb(783):
> RUBY_PLATFORM =~ Merb::Const::WIN_PLATFORM_REGEXP
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mime-types-1.16\lib\mime\types.rb(494):
> system? and (RUBY_PLATFORM =~ @system)
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\mongrel.gemspec(70):#
> if RUBY_PLATFORM !~ /mswin|mingw|java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\mongrel.gemspec(167):#
> unless RUBY_PLATFORM =~ /mswin/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\mongrel.gemspec(185):#
> sh("rake java package") unless RUBY_PLATFORM =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\mongrel.gemspec(188):#
> # sub_project("mongrel_service", :package) if RUBY_PLATFORM =~ /mswin/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\mongrel.gemspec(189):#
> # sh("rake mswin package") unless RUBY_PLATFORM =~ /mswin/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\mongrel.gemspec(207):#
> sub_project("mongrel_service", :install) if RUBY_PLATFORM =~ /mswin|mingw/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\mongrel.gemspec(219):#
> sub_project("mongrel_service", :uninstall) if RUBY_PLATFORM =~ /mswin|mingw/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\mongrel.gemspec(232):#
> sub_project("mongrel_service", :clean) if RUBY_PLATFORM =~ /mswin|mingw/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\bin\mongrel_rails(140):
> if RUBY_PLATFORM !~ /mswin/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\lib\mongrel\configurator.rb(84):
> if RUBY_PLATFORM !~ /mswin|mingw/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\lib\mongrel\configurator.rb(188):
> if RUBY_PLATFORM !~ /mswin|mingw/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\lib\mongrel\configurator.rb(369):
> if RUBY_PLATFORM !~ /mswin|mingw/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\lib\mongrel\rails.rb(176):
> if RUBY_PLATFORM !~ /mswin|mingw/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\mongrel-1.1.5-x86-mingw32\test\testhelp.rb(78):
> result = RUBY_PLATFORM =~ /djgpp|(cyg|ms|bcc)win|mingw/
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\net-ssh-2.0.13\Rakefile(36):
> p.need_tar = true if RUBY_PLATFORM !~ /mswin/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\net-ssh-2.0.13\lib\net\ssh\authentication\agent.rb(6):require
> 'net/ssh/authentication/pageant' if File::ALT_SEPARATOR && !(RUBY_PLATFORM
> =~ /java/)
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\ParseTree-3.0.4\lib\parse_tree.rb(295):
> builder.add_compile_flags "-Werror" unless RUBY_PLATFORM =~ /mswin/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\ParseTree-3.0.4\lib\parse_tree.rb(1123):
> extern_mode = RUBY_PLATFORM =~ /mswin/ ? 'RUBY_EXTERN' : 'extern'
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\pathname2-1.6.2\CHANGES(28):*
> Changed platform checking to use rbconfig instead of RUBY_PLATFORM to avoid
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\ptools-1.1.7\CHANGES(3):* Replaced
> RUBY_PLATFORM with rbconfig check for the sake of other
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rack-1.0.1\lib\rack\rewindable_input.rb(97):
> RUBY_PLATFORM !~ /(mswin|mingw|cygwin|java)/
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rails-2.3.5\CHANGELOG(497):*
> Windows: include MinGW in RUBY_PLATFORM check.  #2982 [okkez000 at gmail.com,
> Kaspar Schiess]
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rails-2.3.5\CHANGELOG(811):*
> Windows: include MinGW in RUBY_PLATFORM check.  #2982 [okkez000 at gmail.com,
> Kaspar Schiess]
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rails-2.3.5\lib\initializer.rb(873):
> if RUBY_PLATFORM =~ /(:?mswin|mingw)/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rails-2.3.5\lib\commands\console.rb(1):irb
> = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rails-2.3.5\lib\commands\dbconsole.rb(35):
> commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rails-2.3.5\lib\commands\runner.rb(21):
> if RUBY_PLATFORM !~ /mswin/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rails-2.3.5\lib\rails_generator\generators\applications\app\app_generator.rb(261):
> ].find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
>
> STDERR.reopen(RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'NUL:' : '/dev/null')
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\railties-3.0.pre\CHANGELOG(494):*
> Windows: include MinGW in RUBY_PLATFORM check.  #2982 [okkez000 at gmail.com,
> Kaspar Schiess]
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\railties-3.0.pre\CHANGELOG(808):*
> Windows: include MinGW in RUBY_PLATFORM check.  #2982 [okkez000 at gmail.com,
> Kaspar Schiess]
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\railties-3.0.pre\lib\rails\configuration.rb(44):
> RUBY_PLATFORM =~ /(:?mswin|mingw)/ ?
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\railties-3.0.pre\lib\rails\commands\dbconsole.rb(45):
> commands += commands.map{|cmd| "#{cmd}.exe"} if RUBY_PLATFORM =~ /win32/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\railties-3.0.pre\lib\rails\commands\runner.rb(21):
> if RUBY_PLATFORM !~ /mswin/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\railties-3.0.pre\lib\rails\generators\actions.rb(243):
> sudo = options[:sudo] && RUBY_PLATFORM !~ /mswin|mingw/ ? 'sudo ' : ''
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\railties-3.0.pre\lib\rails\generators\actions.rb(300):
> if RUBY_PLATFORM =~ /mswin|mingw/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\railties-3.0.pre\lib\rails\generators\rails\app\app_generator.rb(207):
> ].find { |f| File.exist?(f) } unless RUBY_PLATFORM =~ /(:?mswin|mingw)/
>
> STDERR.reopen(RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'NUL:' : '/dev/null')
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rake-0.8.4\lib\rake.rb(2143):
> RUBY_PLATFORM =~
> /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rake-0.8.7\lib\rake.rb(2167):
> RUBY_PLATFORM =~
> /(aix|darwin|linux|(net|free|open)bsd|cygwin|solaris|irix|hpux)/i
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rspec-1.2.8\History.rdoc(342):*
> Consider MinGW as valid RUBY_PLATFORM for --colour option. (patch from Luis
> Lavena). Closes #406.
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rspec-1.2.8\History.rdoc(365):*
> Consider MinGW as valid RUBY_PLATFORM for --colour option. (patch from Luis
> Lavena). Closes #406.
>   ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rspec-1.2.8\bin\autospec(4):system
> (RUBY_PLATFORM =~ /mswin|mingw/ ? 'autotest.bat' : 'autotest'), *ARGV
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rspec-1.2.8\lib\spec\runner\options.rb(162):
> if @colour && RUBY_PLATFORM =~ /mswin|mingw/ ;\
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rspec-1.2.8\spec\spec_helper.rb(16):
> ::RUBY_PLATFORM == 'java'
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rspec-1.2.8\spec\spec\package\bin_spec_spec.rb(8):
> pending "Hangs on JRuby" if RUBY_PLATFORM =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rspec-1.2.8\spec\spec\package\bin_spec_spec.rb(16):
> pending "Hangs on JRuby" if RUBY_PLATFORM =~ /java/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rubygems-update-1.3.5\ChangeLog(3793):
> * changed spec to use the RUBY_PLATFORM for Platform::CURRENT
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\rubygems-update-1.3.5\lib\rubygems.rb(1036):
> @@win_platform = !!WIN_PATTERNS.find { |r| RUBY_PLATFORM =~ r }
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\RubyInline-3.8.3\lib\inline.rb(580):
> RUBY_PLATFORM =~ /darwin9\.[01]/
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\RubyInline-3.8.3\lib\inline.rb(596):
> if WINDOZE and RUBY_PLATFORM =~ /_80\$/ then
>
> ruby-1.8.6p368\lib\ruby\gems\1.8\gems\ZenTest-4.1.4\lib\unit_diff.rb(40):
> WINDOZE = /win32/ =~ RUBY_PLATFORM unless defined? WINDOZE
> nil if RUBY_PLATFORM =~ /mswin|mingw/
> RUBY_PLATFORM =~ /mswin|mingw/
> RUBY_PLATFORM =~ /mswin|mingw/
> LoadError, "Cygwin is a Posix OS." if RUBY_PLATFORM =~ /\bcygwin\b/i
> LoadError, "Not Windows" if RUBY_PLATFORM !~ /mswin|mingw/
>   ruby-1.8.6p368\lib\ruby\site_ruby\1.8\rubygems.rb(1036):
> @@win_platform = !!WIN_PATTERNS.find { |r| RUBY_PLATFORM =~ r }
>
>
> Tomas
>
> -----Original Message-----
> From: ironruby-core-bounces at rubyforge.org [
> mailto:ironruby-core-bounces at rubyforge.org<ironruby-core-bounces at rubyforge.org>]
> On Behalf Of Ivan Porto Carrero
> Sent: Thursday, March 11, 2010 1:19 PM
> To: ironruby-core at rubyforge.org
> Subject: Re: [Ironruby-core] The Proper way to detect the Windows Platform
> in Ruby
>
> I've been using ENV['OS'] == 'Windows_NT' to detect windows relaibly
>
>
> On Thursday, March 11, 2010, Will Green <will at hotgazpacho.org> wrote:
> > http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-platf
> > orm-in-ruby/
> >
> >
> > From one of the JRuby core team.
> > <http://blog.emptyway.com/2009/11/03/proper-way-to-detect-windows-plat
> > form-in-ruby/>--
> > Will Green
> > http://hotgazpacho.org/
> >
> >
>
> --
> ---
> Met vriendelijke groeten - Best regards - Salutations Ivan Porto Carrero -
> Mob: +32.486.787.582
> Web: http://whiterabbitconsulting.eu - http://flanders.co.nz
> Author of IronRuby in Action (http://manning.com/carrero) Microsoft
> IronRuby/C# MVP _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20100311/c784d619/attachment-0001.html>
```