Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem getting character in highline on git bash (via MINGW) on windows #175

Open
otbster opened this issue Nov 2, 2015 · 6 comments
Open
Labels

Comments

@otbster
Copy link

otbster commented Nov 2, 2015

So I may be the only person who has ever had this problem.

I was trying to run a ruby script (to set up an open shift webserver) on git bash (my normal terminal), on windows. It consistently hung at the getting password stage.

Eventually I worked out that the script was using highline, and that, probably due to running git bash on windows (via MINGW), the get_character method was hanging (trying to access windows functions that weren't available or something maybe). Running the script in powershell made it work just fine.

I understand this may be a niche problem.. I just wondered if you were aware of it (/if it would be easy to fix or do something about)

@abinoam
Copy link
Collaborator

abinoam commented Nov 2, 2015

Could you try the prerelease version?

gem install highline --pre

Em Seg, 2 de nov de 2015 12:37, otbster [email protected] escreveu:

So I may be the only person who has ever had this problem.

I was trying to run a ruby script (to set up an open shift webserver) on
git bash (my normal terminal), on windows. It consistently hung at the
getting password stage.

Eventually I worked out that the script was using highline, and that,
probably due to running git bash on windows (via MINGW), the get_character
method was hanging (trying to access windows functions that weren't
available or something maybe)

I understand this may be a niche problem.. I just wondered if you were
aware of it (/if it would be easy to fix or do something about)


Reply to this email directly or view it on GitHub
#175.

@otbster
Copy link
Author

otbster commented Nov 2, 2015

Ok I've tried the prerelease version. With the following simple piece of code:

highline = HighLine.new
puts highline.ask("Password: ") { |q|
q.echo = '*'
q.whitespace = :chomp
}

In version 1.6.21, this works fine in powershell or the command prompt, but hangs in git bash (using MINW).

In version 2.0.0-prerelease, this again works fine in powershell or the command prompt. In git bash, I get the following error:

Password: C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/highline-2.0.0.pre.develop.2/lib/highline/terminal/io_console.rb:17:in echo=': Bad file descriptor (Errno::EBADF) from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/highline-2.0.0.pre.develop.2/lib/highline/terminal/io_console.rb:17:inrestore_mode'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/highline-2.0.0.pre.develop.2/lib/highline/terminal.rb:57:in ensure in raw_no_echo_mode_exec' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/highline-2.0.0.pre.develop.2/lib/highline/terminal.rb:57:inraw_no_echo_mode_exec'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/highline-2.0.0.pre.develop.2/lib/highline.rb:449:in get_response_line_mode' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/highline-2.0.0.pre.develop.2/lib/highline/question.rb:476:inget_response'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/highline-2.0.0.pre.develop.2/lib/highline/question.rb:481:in get_response_or_default' from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/highline-2.0.0.pre.develop.2/lib/highline/question_asker.rb:19:inask_once'
from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/highline-2.0.0.pre.develop.2/lib/highline.rb:188:in ask' from test.rb:6:in

'

(Also, I say it works fine in powershell, but the normal ctrl-c to terminate execution doesn't seem to work in either version while getting a password as above - it has no effect, except for adding a funny extra character to the password).

@abinoam
Copy link
Collaborator

abinoam commented Nov 3, 2015

Hi @otbster ,

Although I couldn't reproduce it the same way you did, your report makes a lot of sense.
The prerelease version of HighLine relies on "io/console" to do most of the "low level" work.
I think git bash may be touching the STDIN in a way that makes ruby io/console not work properly.
Test this one-line script.
In my enviroment it works for Rubyinstaller ruby but raises error for git bash.

ruby -e "require 'io/console'; STDIN.echo = false; a = gets; puts a"

Unfortunately, I will not have much time to try to fix this for at least these next 2 weeks.
I don't understand much of Ruby on Windows, but I can see that mingw32 here on my setup has stty available. So, perhaps we could switch to using it for the low level stuff.

Thanks for reporting, as soon as I have a fix I'll contact you.
We welcome Pull Requests if you're in the mood of fixing it yourself!

@abinoam
Copy link
Collaborator

abinoam commented Nov 3, 2015

@otbster

Could you copy/past here the output of these two commands?

ruby -e "puts RUBY_DESCRIPTION"
ruby -e "puts RUBY_PLATFORM"

@otbster
Copy link
Author

otbster commented Nov 3, 2015

Thanks! Actually I think this was my fault - I just updated git (for a different reason) and during installation it says, if you select the MinTTY emulator for git bash (which is what I use), that windows console programs may not work on it, and you should use "winpty" to run them.

When I then ran
winpty ruby Programming/Ruby/Test.rb
(Test.rb containing the code snippet above that previously didn't work) it works fine, with both version of highline - 1.6.21 and 2.0.0.pre.develop.

So the moral is, pay attention to installation instructions, and use winpty when running windows programs from the MinTTY.

For what it's worth, my RUBY_DESCRIPTION is "ruby 2.0.0p0 (2013-02-24) [x64-mingw32]" and my RUBY_PLATFORM is "x64-mingw32"

@abinoam
Copy link
Collaborator

abinoam commented Nov 3, 2015

Thank you very much for reporting the fix. It will be useful for others that fight the same issue in the future. When I have some time I'll try to work on some "autodetect" features.
I think I'll let this issue open meanwhile so I could easily remember later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants