-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.py
34 lines (31 loc) · 867 Bytes
/
monitor.py
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
import sys
import mmap
import struct
import win32event
buffer_ready = win32event.CreateEvent (
None, 0, 0,
"DBWIN_BUFFER_READY"
)
data_ready = win32event.CreateEvent (
None, 0, 0,
"DBWIN_DATA_READY"
)
buffer = mmap.mmap (0, 4096, "DBWIN_BUFFER", mmap.ACCESS_WRITE)
while True:
#
# Signal that we're ready to accept debug output
#
win32event.SetEvent (buffer_ready)
if win32event.WaitForSingleObject (data_ready, win32event.INFINITE) == win32event.WAIT_OBJECT_0:
buffer.seek (0)
#
# The first DWORD is the process id which generated the output
#
process_id, = struct.unpack ("L", buffer.read (4))
data = buffer.read (4092)
if b"\0" in data:
string = data[:data.index (b"\0")]
else:
string = data
# print "Process %d: %s" % (process_id, string)
print("Process %d: %s" % (process_id, string))