Make generated scripts handle non-zero exit codes

The subprocess.check_output function throws an exception if there
is a non-zero exit code. Let's handle that case: we emit stdout to
stdout whether or not an exception occurred, and we return the same
exit code returned by the subprocess.
Use stdout rather than stderr where appropriate

As suggested by Josh Moore, when logging information messages, we
use stdout, and when emitting warnings and errors, we use stderr.