Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GoAWK seems to buffer more aggressively than (g)awk #47

Closed
benhoyt opened this issue Jan 24, 2021 · 2 comments · Fixed by #80
Closed

GoAWK seems to buffer more aggressively than (g)awk #47

benhoyt opened this issue Jan 24, 2021 · 2 comments · Fixed by #80
Labels
bug Something isn't working

Comments

@benhoyt
Copy link
Owner

benhoyt commented Jan 24, 2021

For example, this script doesn't buffer in (g)awk: one is printed right away, then the sleep, then two. Whereas in GoAWK it buffers, so you see one\ntwo together after the sleep:

$ gawk 'BEGIN { print "one"; system("sleep 3"); print "two" }'

GoAWK waits because it uses buffered output by default. But the gawk docs indicate gawk buffers too. Is it because gawk doesn't buffer when writing directly to the TTY? But the same behavior seems to happen even when (g)awk output is redirected to a file, so I'm not sure.

@benhoyt
Copy link
Owner Author

benhoyt commented Aug 20, 2021

Pushed some old work on this to the flush-better branch.

@xonixx
Copy link
Contributor

xonixx commented Sep 7, 2021

Adding more info to this issue.

Simple script to test:

BEGIN {
  for (i=0; i<10; i++) {
    print i
    system("sleep 1")
    #fflush()
  }
}

I can confirm that gawk, bwk and mawk all output to console at real time (no buffering).
One can "fix" GoAWK by uncommenting the #fflush() line.

The existing buffering behavior can be problematic for some long-running scripts (my https://github.com/xonixx/makesure tool just one example) because it hides the progress of execution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants