I want only the wlan device name at a linux system with python. I could get the device name with shell scripting:
echo /sys/class/net/*/wireless | awk -F'/' '{ print $5 }'
So i want to use this at python with subprocess
.
import shlex
import subprocess
def main():
echo = shlex.split('echo /sys/class/net/*/wireless')
echo_proc = subprocess.Popen(echo, shell=True, stdout=subprocess.PIPE)
awk = shlex.split("awk -F'/' '{ print $5 }'")
awk_proc = subprocess.Popen(awk, stdin=echo_proc.stdout)
print(awk_proc.stdout)
But I get only None
as output. If it is possible, I would prefer a solution with subprocess.run()
. So I replaced Popen
with run
. But then I get the error message AttributeError: 'bytes' object has no attribute 'fileno'
.