我试图调用一个函数get_ethname
到另一个函数get_ethSpeed
,但我无法理解如何得到它叫。如何调用一个函数到另一个函数在Python 2.6
非常感谢先进的投入。
The output of the first function returns the name of the NIC interface on the system as below..
[[email protected]/]# cat intDetail1.py
#!/usr/bin/python
import ethtool
def get_ethname():
inames = ethtool.get_devices()
inameCurr = inames[1]
print inameCurr
return inameCurr
def main():
get_ethname()
main()
[[email protected] /]# ./intDetail1.py
eth0
Below is the main code where i'm trying to call it.
#!/usr/bin/python
import ethtool
import subprocess
def get_ethname():
inames = ethtool.get_devices()
inameCurr = inames[1]
print inameCurr
return inameCurr
def get_ethSpeed():
spd = subprocess.popen("['ethtool', 'get_ethname']", stdout=subprocess.PIPE).communicate()[0]
print spd
return spd
def main():
get_ethname()
get_ethSpeed()
main()
When i run the above code it gives the below error .
File "/usr/lib64/python2.6/subprocess.py", line 1234, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
我的目标是让主运行界面名称上的系统和,然后得到网卡的速度决定使用Linux系统实用ethtool
它告诉接口的速度:
[[email protected] /]# /sbin/ethtool eth0| grep Speed
Speed: 1000Mb/s
Output look of
ethtool eth0
is Below:
[[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
哪些文件名及其树形结构/关系? –
'popen'需要一个参数列表。你已经给它一个字符串。删除双引号,它应该没问题。此外,'python2.6'不再被支持。你应该尽快移到'python2.7'或最好是'python3',而不是稍后。 –
@DaniSpringer,对不起,我不明白你的问题。我只是试图让'eth0'与'ethtool'命令是Linux系统命令,以便接收,说第二个函数需要获取'/ sbin目录/的ethtool eth0'输出的输出。代码中没有调用文件。 – krock1516