Antonio Moreno wrote:
> Robert Klemme wrote:
> > On 20.11.2006 20:24, Antonio Moreno wrote:
> >> I'm trying to code a script for replacing an application which takes
> >> it's input from file descriptors 0 (stdin) and 1 (stdout).
> >
> > This is not possible.  You can only read from stdin and not stdout.
> >
> (snif)

Robert is half right and half wrong (on POSIX compatible platforms
anyway):

readable_fd1 = IO.for_fd(1,"r")
STDERR.puts "FROM STDIN  (fd 0): #{STDIN.read}"
STDERR.puts "FROM STDOUT (fd 1): #{readable_fd1.read}"

You might argue that if someone provides a file on fd 1 it isn't really
stdout, but you can certainly open fd 1 (or any fd) both for reading or
writing if whatever is attached to them supports the mode you want - fd
0, 1 and 2 aren't special in any way to the OS.

You can test the above like this:
  ruby in.rb 1<bar.txt 0<foo.txt

The 1<filename and 0<filename opens the files for input at the file
descriptors specified.

Vidar