您的位置:首页 > 其它

正则表达式1---findall获取tasklist进程信息并存储近文档

2016-09-29 16:21 295 查看
#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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐