简体   繁体   中英

Unable to understand return code of pcregrep when executed from python script

I am trying to parse a set of regular expression using pcregrep command. This command will be executed from python and the output is formatted and stored in python data structures. I am able to execute all the regular expressions except the below one

"^.{159}-{51}\s*\n.{159}Attempting to start (?:ORM(R)?|CPS)  channel\s*\n.*in\s*\n.*init_n_config\s*\n.*H_ICM_C_MCC_CHANNEL_MANAGER\.C\s*\n.*at  line\s*\n.*\d+\s*$"

I am printing the error code and along with the message I get by executing pcregrep command from python.

I am getting error code as 256 and empty message I am using commands utility of python. I am printing cmd_output[0](for return code) and command_output[1] (for error message) I tried executing this from command line and it works perfectly. It prints all the matching lines matching the above regular expression.

Is there anything I am missing here. Only the above regular expression is giving error. Rest of expressions are working absolutely fine.

Return code 256 (when using it via Python subprocess calling methods of various kinds) can mean that the subprocess exited normally with exitcode 1 which for a grep means that it didn't find anything. So this might not be an error but just a failure to find the desired regexp.

Now, that regexp contains several special characters like asterisks and backslashes. There are lots of ways to hand these over in a wrong way so they get interpreted and thus broken in the process. I would suggest to have a look at these points.

It would help if you told us more about how you use this regexp pattern, ie please post the code in which it is used and what is happening with the results etc.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM