From: Tim Hunter Date: 2007-10-15T04:38:30+09:00 Subject: Re: Capturing the output of an external program line by line Aditya Mahajan wrote: > Hi, > > I want to run an external program in ruby. The external program takes a > long time to execute. While running, it gives the information on stdout > about what it is doing. How can I run the external program inside ruby > so that I can capture this information, and display it on stdout? I > tried %x{...}, `...` and system("...."), but all of them give me a > result AFTER the external program has finished executing, not during its > execution. > > Thanks, > Aditya > I've been using this: IO.popen("#{cmd} 2>&1") do |f| while line = f.gets do # do whatever you want with line end end Note that this gets both stdout and stderr. -- RMagick OS X Installer [http://rubyforge.org/projects/rmagick/] RMagick Hints & Tips [http://rubyforge.org/forum/forum.php?forum_id=1618] RMagick Installation FAQ [http://rmagick.rubyforge.org/install-faq.html]