0

I would like to run ip -o -6 addr list | awk '{print $4}' | cut -d/ -f1 in python2, and get the ipv6 addresses. os.system does run the command, but the return value is 0 or 1.

I looked into subprocess.call, what are those args when command becomes complicated like with |?

Tiina
  • 4,285
  • 7
  • 44
  • 73

1 Answers1

0
proc = subprocess.Popen(["ip -o -6 addr list | awk '{{print $4}}' | cut -d/ -f1"], stdout=subprocess.PIPE, shell=True)
ipv6_all = proc.communicate()[0]

Got the idea from stackoverflow question Eric Renouf's answer.

Tiina
  • 4,285
  • 7
  • 44
  • 73