Posts

    Friday 14 March 2014

    Unbuffer to the rescue

    Today I was running a c program which had to print lot of text on the terminal. However after some time it execution used to halt which seemed to be for no reason. This happens because whenever you write something to stdout, it stores it into a buffer till the process gets executed completely. To prevent buffering we can use unbuffer. This did the trick for me:

    unbuffer ./a.out 

    Whenever you redirect some command's output to a file, the output is first stored in buffer and then it s written to the file. Sometimes you may want to avoid this. Specially when the command is generating output continuously.

    unbuffer [command] > [file]

    In order to install it on debian or Ubuntu:

    sudo apt-get install unbuffer