encode stdout messages before writing