From: Siep Korteling Date: 2009-09-03T16:18:36+09:00 Subject: Re: Simple New Ruby Programmer Problem with $stdin.gets Mason Kelsey wrote: > I'm having difficulty getting any command to work to pick up input from > a > screen or what looks like a DOS box when I run a script from SciTE. In > the > following code, which you will recognize as a slightly modified > "basic_client. rb" from Chapter 12 of Beginning Ruby: > > require 'bot' > #bot = Bot.new(:name => ARGV[0], :data_file => ARGV[1]) > bot = Bot.new(:name => "No Sam", :data_file => "bot_data") > puts bot.greeting > while input = $stdin.gets and input.chomp != 'end' > puts '>> ' + bot.response_to(input) > end > puts bot.farewell > > I get the the thing that looks like a DOS Box appear but it is locked up > and > I am unable to input anything. When I kill it by clicking on the close > button, I get the message: > >>ruby basic_client.rb > Hi. I'm No Sam. Want to chat? >>Exit code: -1073741510 > > I have tried just using the gets by itself without the $stdin. with the > same > failure. Do I have to execute this from outside of SciTE? Then where? > I > am running Windows XP. Unfortunately, "Beginning Ruby" does a lite job > on > input from monitors. The way gets is described, on page 203 of the > book, > just does not work. > > Anyway, what is the point for SciTE to display the thing that looks like > a > DOS Box if it is always locked up? > > I bet that the problem is something stupid I am not noticing. Enjoy > revealing my ignorance! And thanks. > > No Sam On windows and using Scite, this simple code has the same behaviour: puts "What is your name? " answer = gets puts "Hi, #{answer}. (any key to exit)" gets This however does work: STDOUT.sync = true #no buffering puts "What is your name? " answer = gets puts "Hi, #{answer}. (any key to exit)" gets If you run this from Scite, the output appears in the left pane. There is no prompt, but the input should be typed there also. hth, Siep -- Posted via http://www.ruby-forum.com/.