From: Robert Klemme Date: 2006-11-21T04:55:09+09:00 Subject: Re: File descriptors 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. > It must also > be able to open another application which in turn also reads from the > above mentioned file descriptors. This is not clear to me: does the other app read from the same fd's (i.e. reading continues in the sub process) or do you want to connect them via a pipe? (The latter is done with IO.popen() or Kernel open as you discovered already). > I've managed to take stdin and put it into stdin of the second app, > though couldn't find the way of opening stdout for reading. > > In http://www.rubycentral.com/book/ref_m_kernel.html#Kernel.open, for > example, states pretty clear that "...The returned IO object may be used > to write to the standard input and read from the standard output of this > subprocess..." > > Does anybody have a clue about this? I'm not very skilled in Ruby, so > any help will be very appreciated. What exactly is your problem? Did you try it and it did not work? Here's a simply sample that works for me irb(main):010:0> open("|cat", "r+") {|io| Thread.new {5.times {|i| io.puts i}; io.flush; io.close_write}; p io.readlines} ["0\n", "1\n", "2\n", "3\n", "4\n"] => nil Note the mode flag. Kind regards robert