"equery check" tool is using a printer function which is using both stdout and stderr. I'm trying to redirect stderr and stdout to the same file (using bash redirection) to save a log. Here is an example: # equery -NC check portage * Checking sys-apps/portage-2.2.20.1 ... !!! /etc/dispatch-conf.conf has incorrect MD5sum !!! /etc/etc-update.conf has incorrect MD5sum 3757 out of 3759 files passed Everything looks fine up to now. The next step is to redirect to a file: # equery -NC check portage &> log.txt # cat log.txt !!! /etc/dispatch-conf.conf has incorrect MD5sum !!! /etc/etc-update.conf has incorrect MD5sum * Checking sys-apps/portage-2.2.20.1 ... 3757 out of 3759 files passed As you can see the order of the lines is now messed. To fix the issue I need to disable python buffering: # PYTHONUNBUFFERED=1 equery -NC check portage &> log.txt # cat log.txt * Checking sys-apps/portage-2.2.20.1 ... !!! /etc/dispatch-conf.conf has incorrect MD5sum !!! /etc/etc-update.conf has incorrect MD5sum 3757 out of 3759 files passed This means that the code should disable the buffering or flushing after every write to preserve the correct order of the output lines.