472,958 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,958 software developers and data experts.

Capturing OutputDebugString information in python

Hello,

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 even
when I make calls to OutputDebugString in other processes, (both
python processes using win32api and actual C++ win32 programs). I
also used mmap to map a file (using fileno -1) to the "DBWIN_BUFFER"
but that buffer appears to be empty all the time no matter the calls
to OutputDebugString.

I have limited experience with this part of windows, but if anyone had
any ideas I'd appreciate it greatly.

Thanks,

Daniel

Oct 16 '07 #1
3 3233
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>
Oct 17 '07 #2
<snip>

Wow, more of a response than I expected, thanks very much for the
research. While not related to the mutex, the problem did appear to
be permission related. For the record, on windows XP

import sys
import mmap
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)
win32event.SetEvent (buffer_ready)
while win32event.WaitForSingleObject (data_ready, 1000) ==
win32event.WAIT_TIMEOUT:
print "Timed out"

print "Was signaled"

appears to work. Write access appears to be required for the buffer
(which I can read and get useful data from:

print buffer.read(4)
print buffer.read(4092)

and no security object. I wasn't the one who figured this out, so I'm
really not sure why it works...but it seems to.
Oct 18 '07 #3
danbrotherston wrote:
<snip>

Wow, more of a response than I expected, thanks very much for the
research. While not related to the mutex, the problem did appear to
be permission related. For the record, on windows XP

import sys
import mmap
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)
win32event.SetEvent (buffer_ready)
while win32event.WaitForSingleObject (data_ready, 1000) ==
win32event.WAIT_TIMEOUT:
print "Timed out"

print "Was signaled"

appears to work. Write access appears to be required for the buffer
(which I can read and get useful data from:

print buffer.read(4)
print buffer.read(4092)

and no security object. I wasn't the one who figured this out, so I'm
really not sure why it works...but it seems to.
Excellent! Do you mind if I add a solution based on this as a
How-Do-I? to my site [1] (suitably accredited, of course)?

TJG

[1] http://timgolden.me.uk/python/win32_how_do_i.html
Oct 18 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Lemon | last post by:
I have written a small .net application to captutre the output from calls to OutputDebugString. However it does not always work, and in general does not seem to capture the output when it is...
3
by: lemony | last post by:
I have written a small .net application to captutre the output from calls to OutputDebugString. However it does not always work, and in general does not seem to capture the output when it is...
1
by: Grant Schenck | last post by:
Hello, I'm on Win2K3. I'm trying to capture OutputDebugString output made by a COM object used from an ASP page but I don't get it. This appears to be due to debug output being generated...
33
by: Joerg Schuster | last post by:
Hello, Python regular expressions must not have more than 100 capturing groups. The source code responsible for this reads as follows: # XXX: <fl> get rid of this limitation! if...
14
by: Brent Burkart | last post by:
I am trying to capture the Windows Authenticated username, but I want to be able to capture the login name that exists in IIS, not Windows. In order to enter my company's intranet through the...
2
by: Stampede | last post by:
Hi guys & girls, I would like to write some kind of "Head-Tracking-Software", which uses a WebCam to react to the movement of the head of the person sitting in front of the monitor. I searched...
6
by: Ed Leafe | last post by:
I've been approached by a local business that has been advised that they need to start capturing and archiving their instant messaging in order to comply with Sarbanes-Oxley. The company is largely...
1
by: Lou | last post by:
In VB6 I would use the API "OutputDebugString" so I could view my internal workings using DBView.exe Is there something native in DotNet that can replace OutputDebugString so I can view whats...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
2
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.