Storing value from a parsed ping

后端 未结 4 974
孤城傲影
孤城傲影 2021-01-28 10:19

I\'m working on some code that performs a ping operation from python and extracts only the latency by using awk. This is currently what I have:

from os import sy         


        
4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-28 10:41

    Use subprocess.check_output if you want to store the output in a variable:

    from subprocess import check_output
    l = check_output("ping -c 1 sitename | awk -F = 'FNR==2 {print substr($4,1,length($4)-3)}'", shell=True) 
    print l
    

    Related: Extra zero after executing a python script

提交回复
热议问题