Xinqi Bao's Git

fflush(stdout) to print line by line if stdout is not a tty
authorJosuah Demangeon <[email protected]>
Tue, 8 May 2018 13:13:56 +0000 (15:13 +0200)
committerAaron Marcher <[email protected]>
Tue, 8 May 2018 13:18:32 +0000 (15:18 +0200)
To reproduce the issue:
$ slstatus -s | tee

then it would print only when the stdout buffer is full, by block
of multiple lines.

fflush() makes sure the line is printed at every loop iteration

slstatus.c

index c1cf8ac..5842b3e 100644 (file)
@@ -98,6 +98,7 @@ main(int argc, char *argv[])
 
                if (sflag) {
                        printf("%s\n", status);
+                       fflush(stdout);
                } else {
                        XStoreName(dpy, DefaultRootWindow(dpy), status);
                        XSync(dpy, False);