"Ferenc Engard" <ferenc / engard.hu> schrieb im Newsbeitrag
news:400A7E96.F52F09C6 / engard.hu...
> Hi all,
>
> Is there a simple way to spawn an external program, feed its stdin, and
> get its stdout?
>
> The problem with popen is, if I want to feed a few MB's of input to it,
> then it hangs (I suspect that its stdout IO buffer is full) before I
> could read out its stdout on the next line. So, the following do not
> work:
>
> io=IO.popen("externalfilter")
> io.write(verybigstring)
> result=io.read

You need at least two threads or non blocking IO. How about:

IO.popen( "cat", "w+" ) do |io|
  r = Thread.new(io) do |reader|
    while ( line = reader.gets )
      line.chomp!
      $stdout.puts line
    end
  end

  (1..100000).each {|i| io.puts i}
  r.join
end

Regards

    robert