小编exc*_*ror的帖子

Python检查shell命令的退出状态

#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
Run Code Online (Sandbox Code Playgroud)

#flash raid固件

OSinfo('MegaCli -adpfwflash -f ' + imagefile + ' -noverchk -a0')
Run Code Online (Sandbox Code Playgroud)

#返回固件闪存状态

?
Run Code Online (Sandbox Code Playgroud)

一个资源建议使用'subprocess.check_output()',但是,我不知道如何将其合并到函数OSinfo()中.

python subprocess exit-code

5
推荐指数
2
解决办法
7276
查看次数

Python 将表转换为字典

问题:命令生成一个表,这使得编写脚本变得非常困难。

解决方案:将表转换为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 
----------------------------------------------------------
Run Code Online (Sandbox Code Playgroud)

字典示例:

{"DG/VD":"0/0", "TYPE":"RAID1", "State":"Optl", …
Run Code Online (Sandbox Code Playgroud)

python dictionary list

4
推荐指数
1
解决办法
3万
查看次数

标签 统计

python ×2

dictionary ×1

exit-code ×1

list ×1

subprocess ×1