如何在Python中构建一个针对OS X或Linux的子进程调用,以执行2个或更多的命令?

2024-05-03 07:43:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在Python脚本中执行以下操作: 更多20151010|ABC.txt | grep QST>;20151010\ u 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()

Tags: 文件oftxt脚本morestdoutgrepend