common: flush stdout before replacing