win32clipboard.GetClipboardData() return string with null characters

A

aurora

I was using win32clipboard.GetClipboardData() to retrieve the Windows
clipboard using code similar to the message below:

http://groups-beta.google.com/group/comp.lang.python/msg/3722ba3afb209314?hl=en

Some how I notice the data returned includes \0 and some characters that
shouldn't be there after the null character. It is easy enough to truncate
them. But why does it get there in the first place? Is the data length
somehow calculated wrong?

I'm using Windows XP SP2 with Python 2.4 and pywin32-203.

aurora
 
R

Roger Upole

I don't get any extra characters. Do they always show up, or is it possible
whatever application put the data on the clipboard put them there ?

Roger
..
 
A

aurora00

It appears to me that some applications put extra garbage data into the
clipboard. win32clipboard may have faithfully returning all of them.

I use this application to show the clipboard content:



import win32clipboard, win32con
def getWinClipboardText():
win32clipboard.OpenClipboard()
d=win32clipboard.GetClipboardData(win32con.CF_TEXT)
win32clipboard.CloseClipboard()
return d

print getWinClipboardText().encode('string_escape')



For example, copying the Python banner from the windows console gets me
this output. Notice the \x00 and garbage characters after that.

----------------------------------------------------------
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit (Intel)]
on win32\r\nType "help", "copyright", "credits" or "lic
ense" for more information.\x00\n ??
----------------------------------------------------------


Some applications appear to put clean data in the clipboard always:
Opera, Putty, Outlook

Some applications appear to include \0 and other crap:
cmd.exe, powerpoint, EmEditor.exe

When I paste, it never appears to be any problem that there maybe
garbage characters in the clipboard. Guess most C based program
correctly null terminates the string.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top