-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtasklist.py
More file actions
40 lines (29 loc) · 879 Bytes
/
tasklist.py
File metadata and controls
40 lines (29 loc) · 879 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/python
"""
Task object which obtains a Windows process list
by running the 'tasklist' command.
Since the output is unpredictable, the following
doctest will return an error, but illustrates
use of the Task object.
>>> tasklist = Tasklist()
>>> tlist = tasklist.run()
>>> print(tlist)
"""
import os
from task import Task
class Tasklist(Task):
def run(self):
# Execute 'tasklist' and obtain
# a file handle connected to the
# output pipe
cmd = "tasklist"
output = os.popen(cmd, mode='r', buffering=1)
# Read from the file and accumulate the
# results into a string
tlist = ""
for line in output.readlines():
tlist = tlist + line
return tlist
if __name__ == "__main__":
import doctest
doctest.testmod()