I want to run arbitrary commands in the shell and get stdout and stderr, for example like this:
cmd = subprocess.run(command, shell=True, universal_newlines=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout = cmd.stdout
stderr = cmd.stderr
However, stdout and stderr might contain random bytestreams. This leads to errors like this:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xfd in position 135: invalid start byte
How can I handle this? Stuff like ? would be ok as result.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…