win32clipboard.GetClipboardData() return string with null characters

aurora00 at gmail.com aurora00 at gmail.com
Thu May 26 15:37:37 EDT 2005


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.




More information about the Python-list mailing list