From: "Ara.T.Howard" Date: 2004-05-06T06:43:56+09:00 Subject: Re: Reading frin STDIN On Wed, 5 May 2004, 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. > > Clayton. perhaps something like unless STDIN.tty? # we are in a pipeline while((line = STDIN.gets)) p line end else end however - you error is in __writing__ where are you writing to? why open up infile - why not simply use STDIN? -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done ===============================================================================