Andrew Seidel wrote:
> I'm having trouble using the pipe to get the file contents and still be
> able to use STDIN in a non-blocking way for a shell-style interactive
> menu.

I think what you're asking is: how can I write a program which does the 
same as this?

    cat /usr/share/file/magic | less

(i.e. less reads its input from stdin, but can also read the terminal).

This is more a Unix question than a Ruby one. Probably the easiest way 
to find out will be to read the source code of 'less'.

The less manpage directs you to http://www.greenwoodsoftware.com/less/ 
from where you can download the source tarball.

The relevant bit:

        /*
         * Try /dev/tty.
         * If that doesn't work, use file descriptor 2,
         * which in Unix is usually attached to the screen,
         * but also usually lets you read from the keyboard.
         */
#if OS2
        /* The __open() system call translates "/dev/tty" to "con". */
        tty = __open("/dev/tty", OPEN_READ);
#else
        tty = open("/dev/tty", OPEN_READ);
#endif
        if (tty < 0)
                tty = 2;

That is: it opens /dev/tty for keyboard input, and falls back to fd 2 if 
that fails. In Ruby that would be something like

  mystdin = IO.open("/dev/tty") rescue IO.for_fd(2)

or if your user library can only talk to STDIN, then perhaps

  STDIN.reopen("/dev/tty")

All untested.
-- 
Posted via http://www.ruby-forum.com/.