# Re: IO.write problem on "raw" Windows

**URL:** <https://www.ruby-forum.com/t/re-io-write-problem-on-raw-windows/108028>\
**Category:** Ruby\
**Created:** [June 28, 2007, 3:11pm UTC](https://www.ruby-forum.com/t/re-io-write-problem-on-raw-windows/108028 "2007-06-28T15:11:28Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![stickstone](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/6f9a4e/32.png) [@stickstone](https://www.ruby-forum.com/u/stickstone)\
**Post date:** [June 28, 2007, 3:11pm UTC](https://www.ruby-forum.com/t/re-io-write-problem-on-raw-windows/108028/1 "2007-06-28T15:11:28Z")

</div>

> 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
