# Getting output of program with some DRb for good measure

**URL:** <https://www.ruby-forum.com/t/getting-output-of-program-with-some-drb-for-good-measure/186475>\
**Category:** Ruby\
**Created:** [April 7, 2010, 4:59pm UTC](https://www.ruby-forum.com/t/getting-output-of-program-with-some-drb-for-good-measure/186475 "2010-04-07T16:59:05Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![christoforever](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@christoforever](https://www.ruby-forum.com/u/christoforever)\
**Post date:** [April 7, 2010, 4:59pm UTC](https://www.ruby-forum.com/t/getting-output-of-program-with-some-drb-for-good-measure/186475/1 "2010-04-07T16:59:05Z")

</div>

I’m running a DRb service which accepts a string and than  
processes that file name on the server side. So I’ve been digging around  
the internet and it seems people have been running into the same  
problems as me. The DRb service will execute the file … but doing so  
will block the DRb service until IO.popen is finished. A way of getting  
around this is to put the executing IO.popen block into a thread …  
which does work. The problem comes when printing to standard out … it  
wont.

IO.popen("#{command\_string}",“w+”) do |ant\_output|  
Thread.new {  
ant\_output.each do |line|  
puts line  
end  
}  
end

I need the output of the given program being run to be printed to the  
screen and I can’t seem to figure it out… any suggestions?

---

<div class="post-metadata">

**Author:** ![christoforever](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@christoforever](https://www.ruby-forum.com/u/christoforever)\
**Post date:** [April 7, 2010, 6:49pm UTC](https://www.ruby-forum.com/t/getting-output-of-program-with-some-drb-for-good-measure/186475/2 "2010-04-07T18:49:58Z")

</div>

Christopher Dancy wrote:

> I’m running a DRb service which accepts a string and than  
> processes that file name on the server side. So I’ve been digging around  
> the internet and it seems people have been running into the same  
> problems as me. The DRb service will execute the file … but doing so  
> will block the DRb service until IO.popen is finished. A way of getting  
> around this is to put the executing IO.popen block into a thread …  
> which does work. The problem comes when printing to standard out … it  
> wont.
> 
> IO.popen("#{command\_string}",“w+”) do |ant\_output|  
> Thread.new {  
> ant\_output.each do |line|  
> puts line  
> end  
> }  
> end
> 
> I need the output of the given program being run to be printed to the  
> screen and I can’t seem to figure it out… any suggestions?

I’ve narrowed down the problem a bit … it seems I get the output from  
within the thread but not from within the ant\_ouput block. So if I do  
something like …

IO.popen("#{command\_string}",“w+”) do |ant\_output|  
Thread.new {  
puts “hello world”  
ant\_output.each do |line|  
puts “fish sticks”  
puts line  
end  
}  
end

I do get the “hello world” but not the “fish sticks” … I’ve tried  
passing the ant\_output block to the thread but still nothing.

---

<div class="post-metadata">

**Author:** ![christoforever](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@christoforever](https://www.ruby-forum.com/u/christoforever)\
**Post date:** [April 7, 2010, 10:05pm UTC](https://www.ruby-forum.com/t/getting-output-of-program-with-some-drb-for-good-measure/186475/3 "2010-04-07T22:05:17Z")

</div>

Brian C. wrote:

> You’re using Windows, I guess? I would be very surprised if DRb blocks  
> in this way under Linux.

Yes I am using windows as well as various version of unix. I’m testing  
it on windows … if I can get it running on windows than everything  
else is a piece of cake.

---

<div class="post-metadata">

**Author:** ![christoforever](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/6de8d8/32.png) [@christoforever](https://www.ruby-forum.com/u/christoforever)\
**Post date:** [April 7, 2010, 9:54pm UTC](https://www.ruby-forum.com/t/getting-output-of-program-with-some-drb-for-good-measure/186475/4 "2010-04-07T21:54:05Z")

</div>

You’re using Windows, I guess? I would be very surprised if DRb blocks  
in this way under Linux.
