Shay Hawkins wrote:
> Well, it seems the problem is primarily occuring with Open3.popen3 
> (which I downloaded the support for Windows from RAA 
> (http://raa.ruby-lang.org/project/win32-open3/)). When I am attempting 
> to call .gets() on the STDERR line, it won't let me input anything into 
> STDIN via .puts() until the .gets() method is over (they are being 
> called in seperate threads).

Sorry, I've read that several times and I still don't understand. Can 
you post a small example which demonstrates the problem, preferably 
standalone?

You should have three IO objects from open3: one writable (connected to 
stdin on the child), and two readable (connected to stdout and stderr on 
the child).

That means you should be able to do

   select([child_out, child_err])

to find out which, if any, has data available for reading. It will block 
if neither is readable, unless you add a timeout:

   select([child_out, child_err], nil, nil, 0)

If that's broken on Windows, your best option is to upgrade to a real 
operating system :-)

However, I believe you should also be able to read from child_out and 
child_err in two separate Ruby threads, which may be the simplest way to 
multiplex them. Try it and see:

  Thread.new(child_out) do |fd|
    while line = fd.gets
      puts line
    end
  end
  Thread.new(child_err) do |fd|
    while line = fd.gets
      puts line
    end
  end

I don't think condition variables will help you here, because you're 
really talking over I/O to a separate process, whilst a ruby 
ConditionVariable is something within a single process.

By the way, remember that gets will block until it gets a newline. 
select() tells you that some data is available, but not how much, nor 
whether there's a newline. So if the other process has sent a prompt 
which doesn't end with newline, gets will hang.

You could try replacing xxx.gets with xxx.readpartial(1024) to read 
whatever data is available.
-- 
Posted via http://www.ruby-forum.com/.