Based on the answer of @AlokThakur (thanks!):
def run_system_command(command):
return_value = os.system(command)
# Calculate the return value code
return_value = int(bin(return_value).replace("0b", "").rjust(16, '0')[:8], 2)
if return_value != 0:
raise RuntimeError(f'The system command\n{command}\nexited with return code {return_value}')