output = subprocess.check_output(["ping", "www.youtube.com"])
print(output.decode())
Либо:
output = subprocess.run(["ping", "www.youtube.com"], capture_output=True, text=True)
print(output.stdout)
PING www.youtube.com (2a00:1450:4010:c06::c6) 56(84) bytes of data.
64 bytes from wide-youtube.l.google.com (2a00:1450:4010:c06::c6): icmp_seq=1 ttl=56 time=131 ms
64 bytes from wide-youtube.l.google.com (2a00:1450:4010:c06::c6): icmp_seq=2 ttl=56 time=88 ms
64 bytes from wide-youtube.l.google.com (2a00:1450:4010:c06::c6): icmp_seq=3 ttl=56 time=327 ms
64 bytes from wide-youtube.l.google.com (2a00:1450:4010:c06::c6): icmp_seq=4 ttl=56 time=86 ms
--- www.youtube.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 86/192/327/115 ms