Storing value from a parsed ping
Question: 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 system
    l = system("ping -c 1 sitename | awk -F = 'FNR==2 {print substr($4,1,length($4)-3)}'")
    print l
    

The `system()` call works fine, but I get an output in terminal rather than
the value storing into l. Basically, an example output I'd get from this
particular block of code would be

    
    
    90.3
    0
    

Why does this happen, and how would I go about actually storing that value
into l? This is part of a larger thing I'm working on, so preferably I'd like
to keep it in native python.


Answer: Use
[`subprocess.check_output`](https://docs.python.org/2/library/subprocess.html#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](http://stackoverflow.com/questions/19914292/extra-zero-after-
executing-a-python-script)

