Force a shell script to fflush

后端 未结 3 1792
深忆病人
深忆病人 2020-12-17 18:08

I was wondering if it was possible to tell bash that all calls to echo or printf should be followed up by a subsequent call to fflush()

3条回答
  •  误落风尘
    2020-12-17 18:52

    If comands use stdio and are connected to a terminal they'll be flushed per line. Otherwise you'll need to use something like stdbuf on commands in a pipe line http://www.pixelbeat.org/programming/stdio_buffering/

    tl;dr: instead of printf ... try to put to the script stdbuf -o0 printf .., or stdbuf -oL printf ...

提交回复
热议问题