简体   繁体   中英

python iteration through stdout

I am able to print the output of my subprocess.popen with:

output = file.stdout.read()
print output

I'm looking for examples of how to iterate through every like of the output to find every instance of the word FontCache and send it to a file. I don't know if I need a for loop or an if statement. I would appreciate a push in the right direction. A link to some examples would be great.

Something like this:

for output in file.stdout.readlines():
    if "FontCache" in output:
        outputfile.write(output)

Of course, you have to open an outputfile to write to.

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