I cannot figure out how to use python's subprocess.run to capture stdout, stderr, and exitcode ... and whatever else can be captured. I also have to use the timeout option because some of the thousands of commands I'm running hang, ie., run interminably. I bet I have missed something obvious, and I apologize. I've spent days on this and cannot figure it out.
Any help you could give me would be much appreciated.
Here's my defective code:
seconds = timeout
try:
proc = subprocess.run(cmd, capture_output=True, timeout=seconds)
except subprocess.TimeoutExpired:
print('This process ran too long:\n' + cmd + '\n')
out, err = proc.communicate()
exitcode = proc.returncode
if len(out) == 0: out="''"
if len(err) == 0: err="''"
#
return exitcode, out, err