From: Alex DeCaria on
I've seen several examples on this forum where folks have used
STDOUT.flush after printing a query to a terminal. For example:

puts "Delete indicated item [yes, no]"
STDOUT.flush
response = gets.chomp

What is the purpose of the 'STDOUT.flush', and is it always necessary to
use it? What are the possible problems if it isn't used?

--Alex
--
Posted via http://www.ruby-forum.com/.

From: Dave Baldwin on

On 28 Apr 2010, at 16:44, Alex DeCaria wrote:

> I've seen several examples on this forum where folks have used
> STDOUT.flush after printing a query to a terminal. For example:
>
> puts "Delete indicated item [yes, no]"
> STDOUT.flush
> response = gets.chomp
>
> What is the purpose of the 'STDOUT.flush', and is it always necessary to
> use it? What are the possible problems if it isn't used?

It forces the output to appear immediately, otherwise it may be held in a buffer for some indeterminate time, usually until enough output has accumulated to make it worth while to commit to the terminal, however as you are waiting for input this threshold will never be reached.

Dave.


From: Alex DeCaria on
Thanks! --Alex
--
Posted via http://www.ruby-forum.com/.

From: Siep Korteling on
Dave Baldwin wrote:
> On 28 Apr 2010, at 16:44, Alex DeCaria wrote:
>
>> I've seen several examples on this forum where folks have used
>> STDOUT.flush after printing a query to a terminal. For example:
>>
>> puts "Delete indicated item [yes, no]"
>> STDOUT.flush
>> response = gets.chomp
>>
>> What is the purpose of the 'STDOUT.flush', and is it always necessary to
>> use it? What are the possible problems if it isn't used?
>
> It forces the output to appear immediately, otherwise it may be held in
> a buffer for some indeterminate time, usually until enough output has
> accumulated to make it worth while to commit to the terminal, however as
> you are waiting for input this threshold will never be reached.
>
> Dave.

Instead of STDOUT.flush-ing multiple times, you can set STDOUT.sync =
true once.
--
Posted via http://www.ruby-forum.com/.

From: Robert Dober on
On Thu, Apr 29, 2010 at 9:16 AM, Siep Korteling <s.korteling(a)gmail.com> wrote:
<snip>
> Instead of STDOUT.flush-ing multiple times, you can set STDOUT.sync =
> true once.

And, please, instead of using STDOUT, please use $stdout, this allows
your users to mock stdout to somewhere else *without* getting constant
redefinition warnings.

Cheers
R.



--
The best way to predict the future is to invent it.
-- Alan Kay

 |  Next  |  Last
Pages: 1 2 3 4 5
Prev: cannot freeze my gems
Next: LOGIN INTO YAHOO