WhenAs documented, when check_output raises an exception, it places the output of the command in the output attribute of the exception object. You can do the following:
try: p = subprocess.check_output(string_command, stderr=subprocess.STDOUT, shell=True, env=env_variables) except subprocess.CalledProcessError as e: print e.output print 'Error running command: ' + '"' + e.cmd + '"' + ' see above shell error' print 'Return code: ' + str(e.returncode) return e.returncode, e.cmd return 0, p