>>> import commands
>>> r = commands.getstatusoutput('wc -l /home/ramdump/Port_COM30_wenshuai/load.cmm')
>>> print r
(0, '101 /home/ramdump/Port_COM30_wenshuai/load.cmm')
>>> print r[1]
101 /home/ramdump/Port_COM30_wenshuai/load.cmm
>>> type(r[1])
<type 'str'>
>>> cmd = 'wc -l /home/ramdump/Port_COM30_wenshuai/load.cmm'
>>>
>>> r = commands.getstatusoutput(cmd)
>>> print r[1]
101 /home/ramdump/Port_COM30_wenshuai/load.cmm
>>>
>>> cmd1 = 'head -c 1024M /home/ramdump/Port_COM30_wenshuai/DDRCS0_0.BIN | strings -n 1 | grep "Linux version"'
>>>
>>> r = commands.getstatusoutput(cmd1)
>>> print r[1]
Linux version 4.4.21-perf-gfef4cd4 (builder@phone-bsp-228-50) (gcc version 4.9 20150123 (prerelease) (GCC) ) #1 SMP PREEMPT Wed Apr 12 04:34:15 CST 2017
Linux version
Linux version 4.4.21-perf-gfef4cd4 (builder@phone-bsp-228-50) (gcc version 4.9 20150123 (prerelease) (GCC) ) #1 SMP PREEMPT Wed Apr 12 04:34:15 CST 2017
>>>
>>> type(r[1])
<type 'str'>
返回的结果是个tuple, (0, xxx) 0表示命令的状态
>>> type(r[0]) <type 'int'>
转载请注明原文地址: https://ju.6miu.com/read-676237.html