From: Brian Candler Date: 2007-06-28T22:02:03+09:00 Subject: Re: IO.write problem on "raw" Windows > On Windows, when running "normal" ruby from a command prompt (Windows' > cmd.exe), it blocks on write. ... > The "other" > program itself is working fine - it's a simple echo-clone. I expect the _other_ program is blocking, because you're not reading its output. That is, you have: ruby -------|pipe1|--------> other <------|pipe2| -------- Ruby is stuffing data into pipe1, but not reading pipe2. Other program reads from pipe1, and stuffs data into pipe2. The O/S will provide some buffering, but eventually the other program will block as it can't write any more to pipe2. Simple solution is to have a separate Ruby thread for reading pipe2: (Note, not tested under Windows) prg = "/bin/cat" pipe = IO.popen(prg, "r+b") t = Thread.new do while line = pipe.gets # or pipe.read(1024) puts "<< #{line}" # optional end pipe.close_read end File.open(ARGV[0], "rb") do |file| pipe.write file.read end pipe.close_write t.join