從外部命令的輸出。雖然我在蟒蛇是新的,我寫了數組列表,我想打印的BIOS信息數組列表?如何在這個腳本中執行外部命令並捕獲輸出並解析它。捕獲和分析的Python裏面
下面的代碼我寫了執行dmidecode |
#!/usr/bin/python
import os
f = os.popen("dmidecode | less")
package = f.read()
print 'Bios Information is:',package
執行上面的代碼之後:使用os.popen()和其輸出到可變稱爲包存儲較少命令須藤蟒sample.py =>輸出是具有如下:
BIOS Information
Vendor: *****
Version: 1.40
Release Date: 09/07/2009
ROM Size: 1024 kB
Characteristics:
PCI is supported
BIOS is upgradeable
BIOS shadowing is allowed
Boot from CD is supported
Selectable boot is supported
BIOS ROM is socketed
EDD is supported
Japanese floppy for NEC 9800 1.2 MB is supported (int 13h)
Japanese floppy for Toshiba 1.2 MB is supported (int 13h)
5.25"/360 kB floppy services are supported (int 13h)
5.25"/1.2 MB floppy services are supported (int 13h)
3.5"/720 kB floppy services are supported (int 13h)
3.5"/2.88 MB floppy services are supported (int 13h)
8042 keyboard services are supported (int 9h)
CGA/mono video services are supported (int 10h)
ACPI is supported
USB legacy is supported
Targeted content distribution is supported
所以,現在我想分析一個價值:供應商,發佈日期&版本,並應提供相關的值。
問題是我必須在上面的腳本中執行外部命令,捕獲輸出並解析它?
那麼有人可以幫助我找出這個問題?
幫我看看,但沒有可用的文件...
更好地給予更多的解釋。告訴他們原來的陣列格式,您的命令(AT-至少樣品) – dhana
你可以參考以下鏈接計算器http://stackoverflow.com/questions/13814428/python-linux-dmidecode-how-to-obtain-hw-info-通過解析 –
我不知道第一個程序與第二個程序有什麼關係。 –