[英]Passing args to subprocess.Popen
需要调用grep from python grep 命令: grep -B 5 -A 5 "make.*Error|Error-" file
尝试了 escaping 的各种组合,正则表达式使其与 subprocess.Popen 一起使用
proc = subprocess.Popen(['grep','-B 5', '-A 5', r'"make.*Error|Error-"', file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
我是否缺少某种转义字符以将该正则表达式正确传递给 grep?
感谢帮助
将 grep 更改为 egrep 并使用以下格式传递正则表达式并且有效!
proc = subprocess.Popen(['egrep','-C 5', r"Error-|make.*Error", 'file.log'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
问题未解决?试试以下方法:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.