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

**URL:** <https://www.ruby-forum.com/t/print-not-showing-immediately-in-output-but-puts-is/150560>\
**Category:** Ruby\
**Created:** [October 9, 2008, 9:30pm UTC](https://www.ruby-forum.com/t/print-not-showing-immediately-in-output-but-puts-is/150560 "2008-10-09T21:30:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [October 9, 2008, 9:30pm UTC](https://www.ruby-forum.com/t/print-not-showing-immediately-in-output-but-puts-is/150560/1 "2008-10-09T21:30:48Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [October 9, 2008, 9:39pm UTC](https://www.ruby-forum.com/t/print-not-showing-immediately-in-output-but-puts-is/150560/2 "2008-10-09T21:39:38Z")

</div>

On Oct 9, 2008, at 3:28 PM, Aryk G. 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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [October 10, 2008, 2:35am UTC](https://www.ruby-forum.com/t/print-not-showing-immediately-in-output-but-puts-is/150560/3 "2008-10-10T02:35:56Z")

</div>

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 B. wrote:

> On Oct 9, 2008, at 3:28 PM, Aryk G. 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 B. [http://agileconsultingllc.com](http://agileconsultingllc.com)  
> removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [October 10, 2008, 11:04am UTC](https://www.ruby-forum.com/t/print-not-showing-immediately-in-output-but-puts-is/150560/4 "2008-10-10T11:04:11Z")

</div>

great, that seems to do it.

---

<div class="post-metadata">

**Author:** ![ericgoodwin](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/c68b51/32.png) [@ericgoodwin](https://www.ruby-forum.com/u/ericgoodwin)\
**Post date:** [October 10, 2008, 3:05am UTC](https://www.ruby-forum.com/t/print-not-showing-immediately-in-output-but-puts-is/150560/5 "2008-10-10T03:05:19Z")

</div>

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,
