带管道的Python2 grep命令

时间:2016-07-15 21:00:22

标签: python variables grep environment

我需要在以下脚本中标识环境变量。

env | grep -i TIMEZONE | cut -c14-18

我做错了什么?我试过了:

command = ['env']
command2 = ['grep']
command2.append('-i')
command2.append('TIMEZONE')
command3 = ['cut']
command3.append('-c14-18')

process=subprocess.Popen(command,stdout=subprocess.PIPE,shell=True)

process2=subprocess.Popen(command2,stdin=process.stdout,stdout=subprocess.PIPE)
process3=subprocess.Popen(command3,stdin=process2.stdout,stdout=subprocess.PIPE)
(out,err) = process3.communicate()
print 'output is :', out

0 个答案:

没有答案