Why subprocess.Popen.communicate() does not return the output?

92 views Asked by At

I have a function for checking network devices by ip for liveness ?

from subprocess import run, Popen, PIPE, DEVNULL
import time

def ping():
    result = Popen(['ping', '192.168.0.1'], stdout=PIPE, stderr=PIPE, 
                     shell=True, text=True)
    out, err = result.communicate()
    time.sleep(5)
    print('Output: ', out)

and called the function

ping()

But nothing is returned as param out. Please help me with this issue! Any help greatly appreciated.

0

There are 0 answers