#coding=utf-8
#使用findall函数,将tasklist命令列出的列表中的进程存入reTestFindall.txt文件中
import os
import re
f=os.popen('tasklist /nh','r') #使用tasklist命令获取进程信息
#oFile=open(r'D:\Python\reTest\reTest2.txt','r')
owFile=open(r'D:\Python\reTest\reTestFindall.txt','w') #打开reTestFindall准备写入文档
for eachLine in f:
readLine=re.findall(r'([\w.]+[\w])\s+(\d+)\s(\w+)\s+(\d+)\s+([\d,]+\sK)',eachLine.rstrip())
#使用正则获取进程信息;
i=0
while i<readLine.__len__(): #逐行写入获取的进程信息
print readLine
owFile.writelines(readLine[i])
owFile.writelines('\t\n')
#owFile.writelines(a)
i+=1
owFile.close()
正则表达式1---findall获取tasklist进程信息并存储近文档
最新推荐文章于 2021-10-18 12:28:43 发布