1 import os
2 import time
3 while True:
4 with open('abc1.txt', 'a+') as f:
5 result2 = str(os.popen('TASKLIST /FI "PID eq 15208"').read())
6 f.write(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())+'\n')
7 f.write(result2)
8 time.sleep(5)
9 print(result2)
10 '''
11 读写模式
12 要了解文件读写模式,需要了解几种模式的区别,以及对应指针
13 r : 读取文件,若文件不存在则会报错
14 w: 写入文件,若文件不存在则会先创建再写入,会覆盖原文件
15 a : 写入文件,若文件不存在则会先创建再写入,但不会覆盖原文件,而是追加在文件末尾
16 rb,wb: 分别与r,w类似,但是用于读写二进制文件
17 r+ : 可读、可写,文件不存在也会报错,写操作时会覆盖
18 w+ : 可读,可写,文件不存在先创建,会覆盖
19 a+ : 可读、可写,文件不存在先创建,不会覆盖,追加在末尾
20 '''