我有一个下面的代码被写入来获得Linux上当前运行的接口的速度,但是当我运行这个脚本时它只是抛出错误:TypeError: execv() arg 2 must contain only strings
。Python TypeError:execv()arg 2必须只包含字符串
将不胜感激任何帮助或想法。
Below is the script:
在下面脚本我创建 1 2个功能)的一个是get_Inf()
这给界面的信息。 2)第二个是get_intSpeed()
,它从第一个functon获取接口名称并将其传递给os命令ethtool
,该命令通过正则表达式进一步解析为仅获取速度,如1000Mb/s
。
#!/grid/common/pkgs/python/v2.7.10/bin/python
import subprocess
import netifaces
import re
''' This snippet is just to get the Speed of the running interface on the System '''
def get_Inf():
Current_inf = netifaces.gateways()['default'][netifaces.AF_INET][1]
return get_Inf
def get_intSpeed():
spd = subprocess.Popen(['/sbin/ethtool', get_Inf()], stdout=subprocess.PIPE).communicate()[0]
pat_match=re.search(".*Speed:\s+(\d+Mb/s)\s+.*", spd) # "d" means any number of digit following the "Mb/s".
speed = pat_match.group(1)
return speed
def main():
print get_intSpeed()
main()
Below is the os command
/sbin/ethtool
which has the Speed information of the Interface along with Other Information.
[[email protected] /]# /sbin/ethtool eth0| grep Speed
Speed: 1000Mb/s
[[email protected] /]# ethtool eth0
Settings for eth0:
Supported ports: [ TP ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: Unknown
Supports Wake-on: g
Wake-on: g
Link detected: yes
我使用的Python版本2.7.10。
请显示整个错误。您发布的代码不会调用'execv'。至少,不直接。 –
@BryanOakley,感谢您的反馈,我意识到我正在回应错误的价值观。 – krock1516