I want to execute the command throughout the python and want to get output back
command is: ls /sys/class/net/ | sed -n '/e.*/p'
it returns the names of interfaces attached which starts with e
with terminal, I am getting the output as: eth0 eth1
, which is expected
But with python, I am executing like this
out = subprocess.Popen(["ls", "/sys/class/net/", " | ", "sed -n '/e.*/p'"],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,)
stdout,stderr = out.communicate()
print(stdout)
the expected output is eth0 eth1
but output:
ls: cannot access ' | ': No such file or directory\nls: cannot access 'sed -n '\''/e.*/p'\''': No such file or directory /sys/class/net/:\neth0\neth1\nlo\nwifi0\nwifi1\nwifi2\n
what is the problem here?