找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 1899|回复: 1

[求助] 使用subprocess模块获取的结果和从OS直接获取的结果不一致

1

主题

1

帖子

1

积分

贫民

积分
1
empo007 发表于 2018-9-24 09:45:18 | 显示全部楼层 |阅读模式
从OS上执行命令:

# ps -ef |grep mhas | grep perl | grep -v grep| awk '{print $10}'  
--conf=/rdsdata/mhas/b995570c-9155-4967-8700-1390dac6c261/conf/b995570c-9155-4967-8700-1390dac6c261.cnf
--conf=/rdsdata/mhas/6c6b5c16-cbc9-45f6-aad1-3b12406854dc/conf/6c6b5c16-cbc9-45f6-aad1-3b12406854dc.cnf

从python上执行结果不一致:

# python
Python 2.7.5 (default, Aug  4 2017, 00:39:18)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import subprocess
>>> mha_ps_cmd = 'ps -ef |grep mhas | grep perl | grep -v grep| awk \'{print $10}\''
>>> res = subprocess.Popen(mha_ps_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
>>> print res
('--conf=/rdsdata/mhas/b995570c-9155-4967-8700-\n--conf=/rdsdata/mhas/6c6b5c16-cbc9-45f6-aad1-\n', '')
>>>

为什么呢?
回复

使用道具 举报

3

主题

34

帖子

34

积分

贫民

积分
34
彭国禹 发表于 2018-9-25 09:39:40 | 显示全部楼层
本帖最后由 彭国禹 于 2018-9-25 09:56 编辑

用subprocess.check_output()函数试一下?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表