From: Adrian Roskrow Date: 2007-01-19T04:51:25+09:00 Subject: Re: Reading from $stdin Hi I must be really stupid but I don't understand this at all, How does the usb scanner connect, to a text editor. I don't know how to do that. I understand how the scanner reads one line at a time, the end of the line being \r\n. What prompts the scanner to read another line, does the \r or \n do it? Barcode reader driver? there is no driver, have I got to write one? Adrian Martin Portman wrote: > Adrian Roskrow wrote: >> 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 >> > > each_with index reads one line at a time. A line needs to be > terminated with an end of line character(s) before it can be read. > > Does your barcode reader insert end of line characters(s) at the end > of the content of the barcode? > > I've used a usb barcode reader (in windows xp) and it does insert > \r\n on the end of each sucessful read. Try the reader out in > a text editor to see if it does. If it doesn't, you'll need to > adopt a different approach than reading lines. Alternatively > in the barcode driver, there may be an option to force it to emit > end of line characters. > > If the barcode reader inserts chars into the editor, just like a > keyboard, > you shouldn't need to redirect the input at all. It should > appear on $stdin. > > Martin. -- Posted via http://www.ruby-forum.com/.