From: Mark Hubbart Date: 2004-05-06T06:23:47+09:00 Subject: Re: Reading frin STDIN On May 5, 2004, at 1:48 PM, Clayton Wozney wrote: > I'm using Ruby to create little command line utilities that read from > STDIN and write to STDOUT so that I can string them together with > pipes. > The I/O part looks like this... > > # open up STDIN for reading > infile = IO.new(0, "r") > > # read from STDIN until EOF > infile.each_line do |line| > > Now, this works fine when I run it from the command line directly (no > pipe). However, when I try to use a pipe like this (for example): > > c:\>type file.txt | ruby_script.rb > > I get this error message: > > The process tried to write to a nonexistent pipe. > ruby_script.rb:23:in `each_line': Bad file descriptor (Errno::EBADF) > from ruby_script.rb:23 > > Is there another way to achieve this effect? Thanx. Not sure why your way wouldn't work, but: any particular reason you aren't using STDIN and STDOUT? STDIN.each_line do |line| # do stuff with line STDOUT.write line end cheers, --Mark