Forum: Ruby "print" not showing immediately in output, but "puts" is

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Eric G. (Guest)
on 2008-10-09 23:30
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?
Rob B. (Guest)
on 2008-10-09 23:39
(Received via mailing list)
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
removed_email_address@domain.invalid
Eric G. (Guest)
on 2008-10-10 04:35
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
> removed_email_address@domain.invalid
Victor G. (Guest)
on 2008-10-10 05:05
(Received via mailing list)
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,
Eric G. (Guest)
on 2008-10-10 13:04
great, that seems to do it.
This topic is locked and can not be replied to.