get_ethname
을 다른 함수 get_ethSpeed
에 호출하려고하는데,이 함수를 호출하는 방법을 이해할 수 없습니다.한 함수를 파이썬 2.6에서 다른 함수로 호출하는 방법 02
고급 입력에 감사드립니다.
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
내 목표는 시스템의 주요 실행 인터페이스 이름에 도착하고 다음 리눅스 시스템 유틸리티 ethtool
를 사용하여 속도가 NIC의 결정 얻을 수있다 인터페이스의 속도를 알려주는 :
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'은 args리스트를 필요로합니다. 대신 문자열을주었습니다. 큰 따옴표를 제거하면 괜찮을 것입니다. 게다가,'python2.6'은 더 이상 지원되지 않습니다. 'python2.7' 또는 바람직하게는'python3'으로 이동해야합니다. –
@DaniSpringer, 죄송합니다. 귀하의 질문에 정확하게 답변을 드릴 수 없습니다. 나는'eth0'을 리눅스 시스템 명령 인'ethtool' 명령으로 받으려고 노력하고 있습니다. 그래서 두번째 기능은'/ sbin/ethtool eth0' 출력의 출력을 가져와야한다고 말합니다. 코드에 호출 된 파일이 없습니다. – krock1516