# Basic syntax:
import subprocess
subprocess.run(["your", "command"], capture_output=True, text=True).stderr
# Where:
# - capture_output=True causes the argument, returncode, stdout, and stderr
# to be captured and returned in an object like:
# CompletedProcess(args=['ls'], returncode=0, stdout='sample_data\n', stderr='')
# - text=True causes the stdout and stderr to be a regular (non-binary) string
# - .stderr allows you to access just the captured stderr from the process
# Example usage:
# I often set things up something like this:
subprocess_output = subprocess.run(["ls", "-l"], capture_output=True, text=True)
if subprocess_output.returncode == 0:
print("subprocess finished without error")
else:
print("The following error occurred:\n {}".format(subprocess_output.stderr))