From: Walton Hoops Date: 2011-02-15T03:06:14+09:00 Subject: Re: Reading/writing to spawned process On 2/12/2011 6:03 PM, Joel F. wrote: > Hi, > > I'd like to spawn a process, then write some stuff to it, then read from > stuff from it, then write more, then read more, etc etc. (Ruby 1.9 and > Windows) > > The way that I've done this is something like: > > ------------------------------ > require 'open3' > require 'io/wait' > > input, output, err = Open3.popen3('cmd') > input.puts 'echo hi' > output.read(output.stat.size) > input.puts 'echo bye' > output.read(output.stat.size) > ------------------------------- > > This seems mostly okay, but I have a couple questions. > > 1. In IO/wait, there's a method called "ready?". If I call "ready?" in > this program, it returns false even when stat.size indicates that there > actually IS in fact data to be read. I'm having trouble understanding > it. > 2. In IO/wait, there's a method called "nread". However, if I call > output.methods.sort, it's not there and I cant use it. I see "ready?" > and "wait", but no "nread". That's odd, when I try on 1.9.2 on Windows, there is no ready?, wait, or nread methods, though they all show a class of IO. My Ruby: C:\Users\walton.hoops>ruby --version ruby 1.9.2p136 (2010-12-25) [i386-mingw32] When I get home I'll try to remember to test on Linux. It could be an OS specific thing. > 3. I'm sure I'm not the first bozo to complain about the > documentation...but the primary documentation for ruby's standard > libraries (ruby-doc.org) is pretty sucky. I'm just feeling frustrated > atm. It took me a lot of hours to come up with the little code that I > have>_<. Is there an alternative site that has more meaningful > documentation? No, your not. Personally I recommend rdoc.info over ruby-doc.org. It is the same documentation, but in my opinion it's much better organized. > I just signed up for the ruby documentation mailing list so I can make > some suggestions...but is there maybe an easier way? It would be nice > if there was just some form that I could fill out and say "on this page > it says X, but it would be more helpful if it said Y". Or even a wiki > version of the API. Not that I am aware of. Actually the best way to get these kinds of changes through would be to clone the repository and submit a documentation patch. Hope that helps some Walton