subprocess output to stdout and to PIPE

前端 未结 2 909
逝去的感伤
逝去的感伤 2021-01-27 07:54

I am using the subprocess module like that:

ping = subprocess.Popen(\'fping.exe 192.168.2.3 196.65.58.69\', stdout=PIPE)
output = ping.stdout.readli         


        
2条回答
  •  春和景丽
    2021-01-27 08:14

    I have found a way to do that here is it:

    for line in os.popen("Fping x.x.x.x x.x.x.x -l"):
        ipList.append(line)
        print(line)
    

    That way, i am able to get the results from the Fping program into the list, and to print it to the screen while it is executing, since the for loop with the os.popen aren't wait for the program to finish, but always looping at every line from the program.

提交回复
热议问题