encode output before writing it to stdout