rhc does not work on windows if install path contains spaces

Solution In Progress - Updated -

Environment

  • OpenShift Enterprise 2
  • OpenShift Online
  • Ruby 2.2
  • Windows used to run rhc tools

Issue

When installing rhc tools on windows with ruby 2.2 the application does not work with the following error:

>rhc --help
'""C:\Program' is not recognized as an internal or external command,
operable program or batch file.

how can this be fixed?

Resolution

This behavior is caused by a bug in rubygems which is fixed in version 2.4.8. Upgrade rubygems to this version or newer to fix it. If this is not possible, a workaround is described below.

In this example ruby is installed into "C:\Program Files\ruby22"

To make rhc work, you need to edit "rhc.bat" file:

C:\Program Files\ruby22\bin\rhc.bat

its contents will look the following way:

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@""C:\Program Files\ruby22\bin\ruby.exe" "C:/Program Files/ruby22/bin/rhc" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@""C:\Program Files\ruby22\bin\ruby.exe" "%~dpn0" %*

note dual double quotemarks at the start of the last line. One of them has to be removed. The file will look like this:

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@""C:\Program Files\ruby22\bin\ruby.exe" "C:/Program Files/ruby22/bin/rhc" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"C:\Program Files\ruby22\bin\ruby.exe" "%~dpn0" %*

After asving the changes rhc should work. If may still fails with an error like this:

>rhc --version
C:/Program Files/ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- dl/import (LoadError)
        from C:/Program Files/ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/Program Files/ruby22/lib/ruby/gems/2.2.0/gems/net-ssh-2.9.2/lib/net/ssh/authentication/pageant.rb:1:in `<top (required)>'
        from C:/Program Files/ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
        from C:/Program Files/ruby22/lib/ruby/site_ruby/2.2.0/rubygems/core_ext/kernel_require.rb:54:in `require'
...

This means that net-ssh-2.9.2 is installed, which is not compatible with ruby 2.2. To fix this upgrade to net-ssh-2.9.3.beta1 or newer:

>gem install net-ssh -v 2.9.3.beta1

Root Cause

This is a bug in rubygems 2.4.5, it creates incorrect BAT files on systems where ruby is installed into a directory that has spaces in its name.

Diagnostic Steps

check the current version by running this command:

>gem --version
2.4.5

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.