[OT]-ish: Can someone explain this?

Abigail abigail at abigail.be
Sun Jul 3 19:06:40 BST 2011


On Sat, Jul 02, 2011 at 02:07:08PM -0700, Randy J. Ray wrote:
> On 07/02/2011 10:04 AM, Andrew Suffield wrote:
>> On Sat, Jul 02, 2011 at 05:32:38PM +0100, Dirk Koopman wrote:
>>> But how come I get output at a shell prompt, and not down a pipe (or
>>> a redirection either)? What special magic is occurring here?
>>
>> If:
>>
>> 1. isatty() is true on the underlying fd of the FILE*
>>
>> and:
>>
>> 2. The string contains \n
>>
>> then printf calls fflush().
>>
>> In your first instance, stdout was your terminal, and in the second it
>> was one end of a pipe.
>
> That was my first thought, but I wasn't 100% sure. Glad to see I was 
> right, and haven't *completely* forgotten my C minutiae...
>


Perl behaves in the same way. Output is by default buffered, but when
the output channel is interactive, output is flushed at each newline.


Abigail


More information about the london.pm mailing list