Alex Wayne wrote: > Tim Hunter wrote: >> Alex Wayne wrote: >>> I have a long running system command that I want to print the output >>> from a ruby script. Basically, this system command runs like a daemon >>> and prints output. So it I just use: >>> >>> `./mycommand foo` >>> >>> The output is completely supressed, and my ruby script simply appears to >>> hang. >>> >>> So how can I execute a system command and have the output streamed back >>> to the terminal before the command finishes? >> >> ri IO::popen > > Hmm, I still can't seem to get this working. I got this: > > IO.popen './mycommand foo' do |f| > puts f.gets > end > > It's doing its job, but I still get no output on the terminal. And to > be clear, when this command is run on its own I definitely get output. Possibly the command is writing to stderr instead of stdout. What happens when you do this? ./mycommand foo >mycommand.stdout 2>mycommand.stderr Does mycommand.stdout have the output, or mycommand.stderr? If the latter, then the command is writing to stderr, and you're going to have to use popen3 instead of plain popen: http://ruby-doc.org/stdlib/libdoc/open3/rdoc/index.html, or if you don't need to distinguish between the two, you could simply re-direct stderr to stdout. I'm doing this from memory but I believe this should work: IO.popen './mycommand foo >2&1' do... -- Posted via http://www.ruby-forum.com/.