Fix stdout()/stderr() helpers for Python 3

On Python 3, the `core.stdout()` and `core.stderr()` helper functions were attempting to concatenate the message encoded as a bytestring with a unicode string containing a newline, which raises a `TypeError`.  Fix this by concatenating the newline first, and then only encoding the result if on Python 2, since Python 3 wants unicode strings anyway.