나는 서브 프로세스 실행이 :파이썬은 json을 리턴하는 서브 프로세스를 반복 하는가?
lshw -json -C network
난 뒤 다음을받을 경우
{
"id" : "network",
"class" : "network",
"claimed" : true,
"handle" : "PCI:0000:00:05.0",
"description" : "Ethernet interface",
"product" : "82545EM Gigabit Ethernet Controller (Copper)",
"vendor" : "Intel Corporation",
"physid" : "5",
"businfo" : "[email protected]:00:05.0",
"logicalname" : "eth0",
"version" : "00",
"serial" : "00:8c:42:77:58:49",
"units" : "bit/s",
"size" : 1000000000,
"capacity" : 1000000000,
"width" : 32,
"clock" : 66000000,
"configuration" : {
"autonegotiation" : "on",
"broadcast" : "yes",
"driver" : "e1000",
"driverversion" : "7.3.21-k8-NAPI",
"duplex" : "full",
"firmware" : "N/A",
"ip" : "10.211.55.10",
"latency" : "0",
"link" : "yes",
"multicast" : "yes",
"port" : "twisted pair",
"speed" : "1Gbit/s"
},
"capabilities" : {
"msi" : "Message Signalled Interrupts",
"bus_master" : "bus mastering",
"cap_list" : "PCI capabilities listing",
"ethernet" : true,
"physical" : "Physical interface",
"logical" : "Logical interface",
"tp" : "twisted pair",
"10bt" : "10Mbit/s",
"10bt-fd" : "10Mbit/s (full duplex)",
"100bt" : "100Mbit/s",
"100bt-fd" : "100Mbit/s (full duplex)",
"1000bt-fd" : "1Gbit/s (full duplex)",
"autonegotiation" : "Auto-negotiation"
}
},
내가 아마도 내가보다가 있다는 경우 (모든 네트워크 인터페이스를 캡처하기 위해이 반복 수 하나는) 내 시스템의 경우가 아닙니다. 또한,이 출력에서 1 또는 2를 어떻게 선택할 수 있습니까? 전체 데이터가 필요하지 않습니다. 당신이 -json
출력 -C
수준의 필터링을 결합 할 수 없습니다 불행히도
def get_nic_data():
lshw_cmd = "lshw -json -C network"
proc = subprocess.Popen(lshw_cmd, shell=True, stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
return proc.stdout
def read_data(proc_output):
import simplejason as json
json_obj = json
json_obj.loads(proc_output)
#Obtain Vendor,Description,Product
#...
#...
json_obj.dumps(obtained_data_here)
#Not sure if this would work this way.
read_data(get_nic_data())
'lshw -json'은 (적어도 내 컴퓨터에서는) 유효한 json 텍스트를 반환하지 않습니다. – jfs
'lshw -json'은 같은 클래스에 대해 여러 개의 결과가있을 경우 유효한 JSON을 반환하지 않습니다. 배열로 있어야하지만'['및']'가 누락 된 것 같습니다. – Raber
@JFSebastian : Bugger, 나는 그랬 으면 좋겠다. OP 부분에서의 실수. 나는 최근에'lshw' 릴리즈 (편리한 데비안 스퀴즈가 내 서버에 있습니다)를 가지고 있지 않았습니다. 누락 된 것,'['및']'대괄호? –