From: Adrian Roskrow Date: 2007-01-18T20:33:08+09:00 Subject: Re: Reading from $stdin Well I have written a small script to read from stdin and guess what, it just sits and does nothing!! I guess I must of got it wrong! Here is small snip-it @number = $stdin.each_with_index do |line, index| printf "%4d %s", index, line end which is just the same as roberts code. I have a question, the bar code reader is connected to a usb port, do I still use stdin (or is this just for the keyboard?) how do I redirect the input to my code? I'm sorry to be asking basic questions but I am new to ruby. Adrian Robert Klemme wrote: > On 17.01.2007 20:53, Adrian Roskrow wrote: >> In answer to your question, no I don't redirect stdin, should I? > > Well, if you don't the script will sit there and wait for you to enter > something via keyboard. And you won't see any output from your version > of the script until you press Ctrl-Z or whatever is the stream > termination sequence on your operating system because the #read call > reads all the way to the end of the stream. So, as Ara said, as long as > there is no end #read cannot return and you don't see any output. The > story is different with a line based implementation like mine. > >> I like your code snippets and will try them out post hast. > > Have fun! > > robert -- Posted via http://www.ruby-forum.com/.