The code below is what I use daily to monitor network connectivity. The returned information could be obtained before yesterday (as of the night before yesterday), but the content read by stdout.read() starting yesterday was empty. The information returned by me directly pinging the host in the CMD window is China Unicom, and the return information obtained by using the call method is also normal. Please help me solve my doubts
cmd='ping 10.9.88.69'
P=subpross.Popen(cmd,stdin=subprocess.PIPE,stdout=subprocess.PIPE,stderr=subprocess.PIPE,shell=True)
reshult=p .stdout.read()
Your command ping 10.9.88.69 will not stop in the Linux environment,
And subprocess.Popen defaults to waiting for the command to end before returning the result, which is blocking
It can be like this
1. Let the ping end early. Add multiple parameters -c to specify the number of pings
2. Change blocking to non-blocking