I'm trying to get WSL to utilize my clipboard so I can update files from the output via xsel -b > my-umatrix-rules.txt. However, I'm getting the following error:

xsel: Can't open display: (null) : Inappropriate ioctl for device

I assume this has something to due with it being separately contained from Windows and therefore the clipboard itself. Is there a way I can get WSL to be able to look at the clipboard?


Solution 1:

From Windows clipboard to WSL

To get information from the Windows clipboard into WSL, use PowerShell and the Get-Clipboard cmdlet, like so:

powershell.exe -c Get-Clipboard > my-umatrix-rules.txt
From WSL to Windows clipboard

To send data to the Windows clipboard from WSL, the easiest way I know is to use clip.exe, like so:

cat my-umatrix-rules.txt | clip.exe

Note, while not applicable to this particular use-case, if you need to capture both output and error of an application in WSL to the Windows clipboard (a common scenario), just use normal Linux redirection, such as:

# <command> 2>&1 | clip.exe
ls kdkdkdkd * 2>&1 | clip.exe