import subprocess
try:
    print('Ping stdout output on success:\n' + subprocess.check_output([
        'ping', '-c', '2', '-w', '2', '1.1.1.1']))
except subprocess.CalledProcessError as e:
    print('Ping stdout output on error:\n' + e.output)
try:
    print('Ping stdout output on success:\n' + subprocess.check_output([
        'ping', '-c', '2', '-w', '2', '8.8.8.8']))
except subprocess.CalledProcessError as e:
    print('Ping stdout output on error:\n' + e.output)
check output from CalledProcessError