On 2016-10-24, Andrew Schorr <
asc...@telemetry-investments.com> wrote:
> On Monday, October 24, 2016 at 8:27:13 AM UTC-4, Kenny McCormack wrote:
>> Suppose you do:
>>
>> $ gawk4 'BEGIN { print "Line 1";system("echo Line 2");print "Line 3"}' > file
>>
>> Is this guaranteed to work as expected? I.e., the output is:
>>
>> Line 1
>> Line 2
>> Line 3
>
> I refer you to the fabulous gawk documentation:
>
>
https://www.gnu.org/software/gawk/manual/html_node/I_002fO-Functions.html
>
> which says:
>
> If you think about what a programmer expects, it makes sense that
> system() should flush any pending output. The following program:
We learn other things here too:
- system("") is recommended as a portable way to flush output,
insinuating that it works on historic Awk implementations.
- the fflush() function was added by Kernighan to his maintained
awk version (I'm guessing One True Awk?) in 1992, and was taken
up by the the Austin group in 2012. A link is given to the issue:
http://austingroupbugs.net/view.php?id=634
On the other hand:
- I can find nothing in the POSIX description of Awk that the
system() function is required to have a any flushing effect. It is
described as simply executing the command in the same manner as the C
system() function.
- The POSIX description of system() is fatter than that in ISO C;
neither ISO C nor POSIX say anything about flushing.
- Four years later, The 2016 online version of POSIX makes no mention
of fflush for Awk. This issue was not integrated:
http://austingroupbugs.net/view.php?id=634