#function运行shell命令
def OSinfo(runthis):
        #Run the command in the OS
        osstdout = subprocess.Popen(runthis, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
        #Grab the stdout
        theInfo = osstdout.stdout.read() #readline()
        #Remove the carriage return at the end of a 1 line result
        theInfo = str(theInfo).strip()
        #Return the result
        return theInfo
#flash raid固件
OSinfo('MegaCli -adpfwflash -f ' + imagefile + ' -noverchk -a0')
#返回固件闪存状态
?
一个资源建议使用'subprocess.check_output()',但是,我不知道如何将其合并到函数OSinfo()中.
问题:命令生成一个表,这使得编写脚本变得非常困难。
解决方案:将表转换为Python字典以提高使用效率。这些表可以有 1 - 20 个不同的虚拟驱动器,并且可能无法设置“名称”等属性。
示例表:
Virtual Drives = 4
VD LIST :
=======
----------------------------------------------------------
DG/VD TYPE   State Access Consist Cache sCC     Size Name
----------------------------------------------------------
0/0   RAID1  Optl  RW     No      RWTD  -   1.818 TB one
1/1   RAID1  Optl  RW     No      RWTD  -   1.818 TB two
2/2   RAID1  Optl  RW     No      RWTD  -   1.818 TB three
3/3   RAID1  Optl  RW     No      RWTD  -   1.818 TB four
4/4   RAID10 Reblg RW     No      RWTD  -   4.681 TB 
----------------------------------------------------------
字典示例:
{"DG/VD":"0/0", "TYPE":"RAID1", "State":"Optl", …