Unix pipe to clipboard with WSL, and in UTF-8

2024-04-17
WSL is good, it will be even better if we can pipe stdout directly into Windows host’s clipboard. Just like ./myscript.sh | to-my-clipboard.sh Note that xclip requires X, so it is not an option. From WSL, we have direct access to Windows executables. The easiest method would be using clip.exe: ./myscript.sh | clip.exe The method works fine if you don’t touch CJK characters or emojis. clip.exe didn’t handle the encoding well since the default codepage in Windows is not 65001(UTF-8). Continue reading