如何在 Python 中为 OS X 或 Linux 的 2 个或更多命令构建子进程调用?

How can I construct a subprocess call in Python for 2 or more commands for OS X or Linux?

我想在 Python 脚本中执行以下操作: 更多 20151010_ABC.txt | grep QST > 20151010_ABC.txt.QST

有很多(将近 1000 个文件)这样的文件。

然后,

在脚本中打开 VIM 编辑器,按需传递 *.txt 或 *.QST 或 NONE 文件,如上。

有什么想法吗? 谢谢!

样本:

import subprocess
more = subprocess.Popen(['more', '20151010_AlterAeon.txt.prsd'], stdout=subprocess.PIPE,)
grep = subprocess.Popen(['grep', 'LVL'], stdin=more.stdout, stdout=subprocess.PIPE,)
feed = subprocess.Popen(['>', '20151010_AlterAeon.txt.prsd.LVL'], stdin=grep.stdout, stdout=subprocess.PIPE,)
end_of_pipe = feed.stdout
#print "Files:", end_of_pipe
for line in end_of_pipe:
    print line.strip()

我的问题解决主要基于以下几点:

result = subprocess.Popen('more 20151010_AlterAeon.txt.prsd | grep LVL >  
20151010_AlterAeon.txt.prsd.LVL',  
stdin=subprocess.PIPE, shell = True)