flush stdout to prevent trailing characters