I have a perl program that prints to stdout, which I then pipe into a file, like this:./skript.pl > file.txt 2>&1This makes the output of that skript buffer. However, I would like to be able to see what the skript is working on at the moment, so I am trying to find a way to enable line buffering in this setup, so that output is printed as soon as a \n appears. (This is the normal behaviour if I just print to the terminal.)I need a solution that is available without installing anything on CentOS.Changing stuff inside the perlscript is an option. I already tried $|, but that is doing more than I want: it messes up the cat file.txt output if the end of the current line is not printed yet.
use line buffering when piping output to file
perl;buffer
You may want to run your script with stdbuf, which has an option for line buffering:stdbuf --output=L --error=L commandThe advantage is that you don't have to modify the code. You can also use stdbuf with utilities which don't have the source code available, or when building such utilities is tricky.