I'm trying to set up a Ruby script that reads from a named pipe in a loop, blocking until input is available in the pipe.

I have a process that periodically puts debugging events into a named pipe:

```
# Open the logging pipe
log = File.open("log_pipe", "w+") #'log_pipe' created in shell using mkfifo
...
# An interesting event happens
log.puts "Interesting event #4291 occurred"
log.flush
...

```

I then want a separate process that will read from this pipe and print events to the console as they happen. I've tried using code like this:

```
input = File.open("log_pipe", "r+") 
while true
  puts input.gets  #I expect this to block and wait for input
end
# Kill loop with ctrl+c when done

```

I want the `input.gets` to block, waiting patiently until new input arrives in the fifo; but instead it immediately reads `nil` and loops again, scrolling off the top of the console window.

Two things I've tried: 

1. I've opened the input fifo with both "r" and "r+"--I have the same problem either way;
2. I've tried to determine if my writing process is sending EOF (which I've heard will cause the read fifo to close)--AFAIK it isn't.

SOME CONTEXT:

If it helps, here's a 'big picture' view of what I'm trying to do:

I'm working on a game that runs in RGSS, a Ruby based game engine. Since it doesn't have good integrated debugging, I want to set up a real-time log as the game runs--as events happen in the game, I want messages to show up in a console window on the side. I can send events in the Ruby game code to a named pipe using code similar to the writer code above; I'm now trying to set up a separate process that will wait for events to show up in the pipe and show them on the console as they arrive. I'm not even sure I need Ruby to do this, but it was the first solution I could think of.

Note that I'm using `mkfifo` from cygwin, which I happened to have installed anyway; I wonder if that might be the source of my trouble.

If it helps anyone, here's exactly what I see in irb with my 'reader' process:

```
irb(main):001:0> input = File.open("mypipe", "r")
=> #<File:mypipe>
irb(main):002:0> x = input.gets
=> nil
irb(main):003:0> x = input.gets
=> nil

```

I don't expect the `input.gets` at 002 and 003 to return immediately--I expect them to block.