我想知道是否可以过滤python
脚本的标准输出。它使用子进程[*] 1调用另一个脚本(ksh
),并在每次执行某些操作时将消息写入控制台。我想要压缩那条消息,它总是以子串foo
开始。
我该怎么做?
感谢您的时间。
编辑[*] 1 stdout
将其重定向到subprocess.PIPE
编辑方法的代码和免责声明:我知道shell=True
非常气馁,但我无法使其工作。此方法调用ksh
自定义shell,该shell调用另一个名为nexec
def runNexec(self, command='pwd'):
args=['nsh', '-c', 'nexec ' + self.name +' '+ command,'shell=True']
p = Popen(args, stdout=PIPE, stderr=PIPE)
(out, err) = (p.communicate())
status = p.poll()
if status != 0:
return (1,log.log_error(err))
else:
return (0,out.splitlines())