# Popen broken in win32?

**URL:** <https://www.ruby-forum.com/t/popen-broken-in-win32/54816>\
**Category:** Ruby\
**Created:** [March 14, 2006, 4:45pm UTC](https://www.ruby-forum.com/t/popen-broken-in-win32/54816 "2006-03-14T16:45:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [March 14, 2006, 4:45pm UTC](https://www.ruby-forum.com/t/popen-broken-in-win32/54816/1 "2006-03-14T16:45:36Z")

</div>

I am running a visual studio command line build via IO.popen, like so:

IO.popen(“devenv my\_solution.sln /rebuild ‘release Win32’”) do | pipe |  
pipe.each\_line { |line| puts line }  
end

While if I run this command in a cmd window, I get hundreds of lines of  
output. I can redirect the output on the command line like this:  
devenv my\_solution.sln /rebuild 'release Win32 \> output.txt, and I don’t  
lose any output. So I am pretty sure the build output is going to  
STDOUT, not STDERR.

ruby -v  
ruby 1.8.4 (2005-12-24) [i386-mswin32]

I have also tried replacing the pipe.each\_line with str = pipe.read, but  
got the same results.

Thanks,

~S

---

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [March 14, 2006, 5:25pm UTC](https://www.ruby-forum.com/t/popen-broken-in-win32/54816/2 "2006-03-14T17:25:27Z")

</div>

Shea M. wrote:

> STDOUT, not STDERR.
> 
> ruby -v  
> ruby 1.8.4 (2005-12-24) [i386-mswin32]
> 
> I have also tried replacing the pipe.each\_line with str = pipe.read, but  
> got the same results.
> 
> Thanks,
> 
> ~S

The solution to make it work seems to be this:

l\_cmd = “devenv my\_solution.sln /rebuild ‘release Win32’”  
IO.popen(“cmd.exe”, IO::RDWR) do | pipe |  
pipe.puts l\_cmd  
pipe.each\_line { |line| puts line }  
end

I am assuming that this is a bug, and not a ‘feature’.

~S

---

<div class="post-metadata">

**Author:** ![Shea\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/ecccb3/32.png) [@Shea\_M](https://www.ruby-forum.com/u/Shea_M)\
**Post date:** [March 14, 2006, 5:31pm UTC](https://www.ruby-forum.com/t/popen-broken-in-win32/54816/3 "2006-03-14T17:31:31Z")

</div>

> The solution to make it work seems to be this:
> 
> l\_cmd = “devenv my\_solution.sln /rebuild ‘release Win32’”  
> IO.popen(“cmd.exe”, IO::RDWR) do | pipe |  
> pipe.puts l\_cmd  
> pipe.each\_line { |line| puts line }  
> end

Oops, the above, leaves the cmd shell open, this is better:  
l\_cmd = “devenv my\_solution.sln /rebuild ‘release Win32’”  
IO.popen(“cmd.exe /c #{l\_cmd}”) do | pipe |  
pipe.each\_line { |line| puts line }  
end
