Results 1 to 5 of 5

Thread: How to Flush Output Buffer in Ruby?

  1. #1
    Join Date
    Nov 2005
    Beans
    349
    Distro
    Ubuntu 13.04 Raring Ringtail

    Smile How to Flush Output Buffer in Ruby? [RESOLVED]

    I'm debugging a Monte Carlo simulation written in Ruby. At the beginning of each Monte Carlo trial, my code does a
    Code:
    puts trialNum
    where trialNum is the iteration counter. Unfortunately, this output often fails to appear in until the program has finished running. I guess the output is being buffered. Is there a way to flush the buffer, so that these little progress reports appear in real time?
    Last edited by Ubuntist; July 1st, 2007 at 02:40 PM. Reason: Changed title to indicate that problem has been resolved.

  2. #2
    Join Date
    Jun 2007
    Beans
    538

    Re: How to Flush Output Buffer in Ruby?

    puts trialNum
    $stdout.flush # (depends on OS, but should work)

  3. #3
    Join Date
    Nov 2005
    Beans
    349
    Distro
    Ubuntu 13.04 Raring Ringtail

    Thumbs up Re: How to Flush Output Buffer in Ruby?

    Yo, dude, thanks! It works a treat.

  4. #4
    Join Date
    Jan 2009
    Beans
    1

    Re: How to Flush Output Buffer in Ruby?

    didnt work for me, i get this error

    cliente.rb:16: undefined local variable or method `stdout' for main:Object (NameError)

  5. #5
    Join Date
    Feb 2006
    Location
    Vancouver, BC, Canada
    Beans
    318

    Re: How to Flush Output Buffer in Ruby?

    Quote Originally Posted by santi740 View Post
    didnt work for me, i get this error

    cliente.rb:16: undefined local variable or method `stdout' for main:Object (NameError)
    It's $stdout, not stdout.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •