我必须捕获tshark -D
使用 python的输出subprocess
。这是tshark -D
输出,
$ tshark -D
1. eth0
2. any (Pseudo-device that captures on all interfaces)
3. lo
并使用它给出的python,
>>> import subprocess
>>> p = subprocess.Popen(["tshark", "-D"], stdout=subprocess.PIPE) ###1
>>> 1. eth0
2. any (Pseudo-device that captures on all interfaces)
3. lo
>>> p = subprocess.Popen(["tshark", "-D"], stderr=subprocess.PIPE,stdout=subprocess.PIPE) ###2
>>> p.stderr.read()
'1. eth0\n2. any (Pseudo-device that captures on all interfaces)\n3. lo\n'
>>> p.stdout.read()
''
在 #1 中,输入命令后会给出输出。在#2 中,需要的输出进来stderr
。为什么会给出这样的结果?