danbrotherston wrote:
I am trying to get the output from the win32 platform command
OutputDebugString. I have used the following C++ code as a
guideline:
http://groups.google.com/group/micro...3c957675242c7e
And I have been able to translate most things into python, but I have
been unable to get it to work. I use the pywin extensions to call
CreateEvent and create the required events. But when I wait on the
event using the WaitOnSingleEvent call, it hangs indefinitely.
Well, unhelpfully, I can't get it to work, either! I used the code below,
so you might compare with yours to see if we're doing the same thing,
but I can't see any obvious problems. This page which you may have seen:
http://www.unixwiz.net/techtips/outputdebugstring.html
is useful, but the security problem they identify with the mutex
doesn't seem to apply when I'm a local admin and my two processes
are run on my desktop.
I did have a dig inside the mmapmodule.c code (for the second time
in a month!) and a few differences do emerge from the posted code:
- The python code uses a NULL security attribute, which should mean:
full access to everyone.
- The python code assumes an access of write means: create the file
mapping for PAGE_READWRITE and map it for WRITE, while the posted
code maps for READ only.
Neither of these seems terribly significant, but who knows? The
problem of course is that the OutputDebugString function is designed
to fail silently, so you've no idea which part of your debugger is
causing it to fail -- or something else altogether.
I've scanned (very quickly) the MS groups on Google and I can't see
anything helpful. Hopefully someone else on this or on the win32
list has more experience & expertise than I do here. (Which wouldn't
be hard!)
TJG
<code>
import sys
import mmap
import win32security
import win32event
def main (args):
sd = win32security.SECURITY_DESCRIPTOR ()
dacl = win32security.ACL ()
sd.SetSecurityDescriptorDacl (1, dacl, 0)
sa = win32security.SECURITY_ATTRIBUTES ()
sa.SECURITY_DESCRIPTOR = sd
buffer_ready = win32event.CreateEvent (sa, 0, 0, "DBWIN_BUFFER_READY")
data_ready = win32event.CreateEvent (sa, 0, 0, "DBWIN_DATA_READY")
buffer = mmap.mmap (0, 4096, "DBWIN_BUFFER", mmap.ACCESS_READ)
win32event.SetEvent (buffer_ready)
while win32event.WaitForSingleObject (data_ready, 1000) == win32event.WAIT_TIMEOUT:
pass
if __name__ == '__main__':
main (sys.argv[1:])
</code>