1

I've been running quite a few ruby console scripts in cygwin terminal under windows xp with no problems so far using ruby 1.9.3-p28 from rubyinstaller.

All of a sudden now I'm noticing this odd behaviour. I have the following simple code:

while input = gets
  puts input
  puts "ok"
end

which gives no output whatsoever in console. It seems the input = gets part makes the while cycle hang for some reason. If I change the script this way

while true
  puts "ok"
end

while cycle works as expected, but if I add the line input = gets just below puts "ok" it's hanging again, and strange thing is it doesn't even write "ok" to console just before hanging. It seems it's doing completely nothing and windows task manager shows ruby process has no activity at all.

I've also tried with loop do end cycle, but behaviour is exactly the same.

Instead, things works ok if I use no cycle at all.

All I can understand is that it's related to stdin gets method inside a cycle.

I'd like if someone could help me debug what is exactly happening here.

UPDATE (more info): script correctly works in windows command shell.

4

1 に答える 1

1

私はそれを修正しました:

require 'win32console' if RbConfig::CONFIG['host_os'].include? "mingw32"

これまでのところ、「win32console」を「colorize」gemと一緒に使用して色を機能させるだけで、色を出力していない場合でも、「win32console」gemをcygwin端末で使用する必要があることを知りませんでしたWindows XP ネイティブ コマンド プロンプト。

これについては、コードの先頭にリマインダーを貼り付けます...

于 2013-04-16T18:41:09.067 に答える