Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Link to the documentation
Source Link
user4815162342
  • 158.8k
  • 22
  • 350
  • 418

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 

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 

As 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 
Source Link
user4815162342
  • 158.8k
  • 22
  • 350
  • 418

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