Last active
August 29, 2015 14:01
-
-
Save toolness/67405092d5fd28119f66 to your computer and use it in GitHub Desktop.
ctypes-based Python version of OS X's pbpaste command for Windows.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
import ctypes | |
# This is adapted from code found via: | |
# http://nullege.com/codes/search/ctypes.windll.user32.OpenClipboard | |
ctypes.windll.user32.OpenClipboard(0) | |
pcontents = ctypes.windll.user32.GetClipboardData(1) # 1 is CF_TEXT | |
data = ctypes.c_char_p(pcontents).value | |
ctypes.windll.user32.CloseClipboard() | |
if data is not None: | |
sys.stdout.write(data.replace('\r\n', '\n')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Windows
clip.exe
program can be used as an alternative topbcopy
, too.