python will get output of grep -q from the subprocessor

I dont think you need to look at stdout & stderr.

All you need to do is to look at the return code:

process1 = Popen("grep -q string file.txt",shell=True,stdout=PIPE)
process1.communicate()
print(f"grep returned {process1.returncode}")

grep will return zero when something is found.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top