"print" not showing immediately in output, but "puts" is

Discussion in 'Ruby' started by Aryk Grosz, Oct 9, 2008.

  1. Aryk Grosz

    Aryk Grosz Guest

    Several times I have come across this issue. It seems to be dependent on
    the environment, but I'll do a "print 'string'" and it wont show up
    UNTIL I do a "puts". Then both strings will show up in the output window
    in one shot.

    Do you know how I can fix it to work properly?
    --
    Posted via http://www.ruby-forum.com/.
     
    Aryk Grosz, Oct 9, 2008
    #1
    1. Advertising

  2. On Oct 9, 2008, at 3:28 PM, Aryk Grosz wrote:

    > Several times I have come across this issue. It seems to be
    > dependent on
    > the environment, but I'll do a "print 'string'" and it wont show up
    > UNTIL I do a "puts". Then both strings will show up in the output
    > window
    > in one shot.
    >
    > Do you know how I can fix it to work properly?



    It's your terminal doing line buffering on the output.

    Try:
    $stdout.flush = true

    Then see how it works for you.

    -Rob

    Rob Biedenharn http://agileconsultingllc.com
     
    Rob Biedenharn, Oct 9, 2008
    #2
    1. Advertising

  3. Aryk Grosz

    Aryk Grosz Guest

    Thanks for the information Rob.

    Should I run this line before each "print" command or do I just need to
    run it once upon application startup?


    Rob Biedenharn wrote:
    > On Oct 9, 2008, at 3:28 PM, Aryk Grosz wrote:
    >
    >> Several times I have come across this issue. It seems to be
    >> dependent on
    >> the environment, but I'll do a "print 'string'" and it wont show up
    >> UNTIL I do a "puts". Then both strings will show up in the output
    >> window
    >> in one shot.
    >>
    >> Do you know how I can fix it to work properly?

    >
    >
    > It's your terminal doing line buffering on the output.
    >
    > Try:
    > $stdout.flush = true
    >
    > Then see how it works for you.
    >
    > -Rob
    >
    > Rob Biedenharn http://agileconsultingllc.com
    >


    --
    Posted via http://www.ruby-forum.com/.
     
    Aryk Grosz, Oct 10, 2008
    #3
  4. [Note: parts of this message were removed to make it a legal post.]

    STDOUT.flush needs to be put after output, but before a gets call, for
    example... however, STDOUT.sync=true can be done just once, and it sets the
    output to be flushed each time there is output.
    Warmest Regards,

    On Thu, Oct 9, 2008 at 7:33 PM, Aryk Grosz <>wrote:

    > Thanks for the information Rob.
    >
    > Should I run this line before each "print" command or do I just need to
    > run it once upon application startup?
    >
    >
    >
     
    Victor H. Goff III, Oct 10, 2008
    #4
  5. Aryk Grosz

    Aryk Grosz Guest

    Aryk Grosz, Oct 10, 2008
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keto
    Replies:
    0
    Views:
    1,024
  2. zuzu
    Replies:
    21
    Views:
    295
  3. Michael Brooks
    Replies:
    22
    Views:
    434
    Rick DeNatale
    Mar 27, 2007
  4. John Maclean

    Using print and puts for output

    John Maclean, Dec 13, 2007, in forum: Ruby
    Replies:
    2
    Views:
    106
    Rick DeNatale
    Dec 13, 2007
  5. Raj Singh
    Replies:
    4
    Views:
    153
    Ryan Ingram
    Jan 29, 2008
Loading...

Share This Page