On 21.11.2006 01:21, Vidar Hokstad wrote: > 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. Thanks for elaborating! Actually I was not aware that you can do this. However, even if it is possible I would not do it as the general convention is that 1 should be written to and 0 be read from only. After all, what do you gain by reading from FD 1 if nothing writes to it? :-) But, as we have seen, the issue at hand was about connecting parent and child process through pipes. Kind regards robert