I would like to get the first interface that is up on a linux machine. I am using subproces and I have the following piece of code :
def get_eth_iface():
awk_sort = subprocess.Popen( ["-c", "ifconfig | cut -d ' ' -f 1 | grep eth | head -n 1" ], stdin= subprocess.PIPE, shell=True )
awk_sort.wait()
output = awk_sort.communicate()[0]
But with this result will be printed to the console and won't be saved to the variable. How can I redirect this to the variable ?