python 使用shell 命令
2017-04-14 16:45
267 查看
>>> 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'>
>>> 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'>
相关文章推荐
- python中使用shell命令的输出作为其变量的方法
- MacOS python shell下使用命令运行ok,但是在eclipse上运行失败
- python中如何使用shell命令, 及python 与shell 中的变量相互通信
- python-执行shell命令的模块使用
- Python之使用subprocess处理shell命令
- python执行使用shell命令方法分享
- python 使用subprocess模块来执行shell命令
- 转变思维--使用Python生成Shell命令,批量执行程序
- Python中, 使用setup.py和console_scripts参数创建安装包和shell命令
- linux使用Python上秘钥远程登录ssh执行shell命令
- 【python中调用shell命令使用PIPE】使用PIPE作为stdout出现假卡死的情况——将stdout重定向为输出到临时文件
- 使用Python生成Shell命令,批量执行程序代码解析
- linux 使用 java 程序执行 shell命令
- 升级Python2.7导致使用pip等命令安装模块失败
- sed 命令的使用及shell判断语句
- Linux使用技巧:linux下将命令值赋给shell变量
- python基础之使用os.system来执行系统命令
- linux shell 管道命令(pipe)使用及与shell重定向区别
- awk学习笔记四-使用Shell 命令
- paip.执行shell cmd 命令uapi java php python总结