Need to call grep from python grep command: grep -B 5 -A 5 "make.*Error|Error-" file
Tried various combinations of escaping the regex make it work with subprocess.Popen
proc = subprocess.Popen(['grep','-B 5', '-A 5', r'"make.*Error|Error-"', file], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
Am I missing some sort of escape characters to pass that regex correctly to grep?
Appreciate the help
changed grep to egrep and used the following format to pass regex and it worked!
proc = subprocess.Popen(['egrep','-C 5', r"Error-|make.*Error", 'file.log'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.