Forum: Ruby popen broken in win32?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
F330a44fdf083a7a30488efc47759f3f?d=identicon&s=25 Shea Martin (Guest)
on 2006-03-14 16:45
(Received via mailing list)
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
F330a44fdf083a7a30488efc47759f3f?d=identicon&s=25 Shea Martin (Guest)
on 2006-03-14 17:25
(Received via mailing list)
Shea Martin 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
F330a44fdf083a7a30488efc47759f3f?d=identicon&s=25 Shea Martin (Guest)
on 2006-03-14 17:31
(Received via mailing list)
>
> 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
This topic is locked and can not be replied to.