2017-03-16 38 views
0

在蟒如果我有接口= netifaces.interfaces(),其是返回的列表: [「LO」,「eth0的」,「ETH1」]蟒列表在子過程for循環

如何我環在列表中傳遞lo和eth0,將eth1轉換爲ethtool的幾個子進程調用?

subprocess.call(['ethtool %'] interfaces) --- lo 
subprocess.call(['ethtool %'] interfaces) --- eth0 
subprocess.call(['ethtool %'] interfaces) --- eth1 

我想在我的列表界面的項目數量運行ethtool的,但每一遍我想替換下一個項目在接口列表並傳遞到subprocess.call。

+0

任何你不能把它放在for循環中的原因,因爲你的問題標題說明了什麼? – Shadow

+0

是的。我想把它放在for循環中,但是如何在每次傳遞中傳遞接口列表中的每個項目? 接口在接口: subprocess.call(['ethtool%'] ????) – god

+0

我明白了。我已經添加了答案。你傳遞給'call'的列表是一個參數列表。所以只需提供界面作爲列表中的第二項。 – Shadow

回答

2

據我所知,你只是想爲循環做一個正常的...

interfaces = netifaces.interfaces() 
for interface in interfaces: 
    subprocess.call(["ethtool", interface]) 
0
for interface in interfaces: 
    print("[+] Fetching LLDP info for ", interface) 
    subprocess.call(['lldptool', '-t', '-n', '-i', interface]) 
    print("[+] Printing ethtool info for ", interface) 
    subprocess.call(['ethtool', interface]) 

我證明,我是路過的接口子進程調用的外部,一旦我把它放在[]中,按預期工作。我喜歡這個網站!謝謝你的影子

+0

歡迎來到Stack Overflow。這裏的約定是upvote(點擊向上箭頭)和/或接受(點擊複選標記,使其變成綠色)幫助你的答案。 – tripleee