Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用subprocess.Popen中的列表在python中的另一个列表中存储一些值?_Python_List_For Loop_Subprocess_Popen - Fatal编程技术网

如何使用subprocess.Popen中的列表在python中的另一个列表中存储一些值?

如何使用subprocess.Popen中的列表在python中的另一个列表中存储一些值?,python,list,for-loop,subprocess,popen,Python,List,For Loop,Subprocess,Popen,我在一个列表(maclist)中存储了2个mac地址,并将它们从一个文件中“灰色化”。我认为for循环工作正常,但输出(iplist)中没有打印任何内容 该文件包含mac地址和ip,因此通过使用mac我可以获得ip iplist = [] leasefile="/var/lib/misc/dnsmasq.leases" p9 = subprocess.Popen(["cut", "-f", "2,3,4", "-s", "-d", " ", leasefile], stdout=subproc

我在一个列表(maclist)中存储了2个mac地址,并将它们从一个文件中“灰色化”。我认为for循环工作正常,但输出(iplist)中没有打印任何内容

该文件包含mac地址和ip,因此通过使用mac我可以获得ip

iplist = []
leasefile="/var/lib/misc/dnsmasq.leases"

p9 = subprocess.Popen(["cut", "-f", "2,3,4", "-s", "-d", " ", leasefile], stdout=subprocess.PIPE)

for line in p9.stdout:
    for i in range(len(maclist)):
        p10 = subprocess.Popen(["grep", str(maclist[i])], stdin=p9.stdout,
            stdout=subprocess.PIPE)

        p11 = subprocess.Popen(["cut", "-f", "2", "-s", "-d", " "], encoding="utf8", 
            stdin=p10.stdout, stdout=subprocess.PIPE)

        for line2 in p11.stdout:
            iplist.append(line2.rstrip('\n'))
    print(iplist)

为什么你要用子程序而不是用Python读取文件?为什么你要用子程序而不是用Python读取文件?