Encode if necessary before writing to standard out