问题
Using the Linux Subsystem for Windows (LSW), clip.exe
can be used to copy data to the windows clipboard:
$ clip.exe /?
CLIP
Description:
Redirects output of command line tools to the Windows clipboard.
This text output can then be pasted into other programs.
Parameter List:
/? Displays this help message.
Examples:
DIR | CLIP Places a copy of the current directory
listing into the Windows clipboard.
CLIP < README.TXT Places a copy of the text from readme.txt
on to the Windows clipboard.
Is there any way to pipe FROM the clipboard? Examples of intended use:
$ paste.exe > foo.txt
$ paste.exe | tr , '\n' | clip.exe
回答1:
Solution
This prints the Windows' clipboard to stdout:
powershell.exe Get-Clipboard
Examples
$ echo "hello" | clip.exe
$ powershell.exe Get-Clipboard
hello
$ date +%Y-%m-%d | clip.exe
$ powershell.exe Get-Clipboard
2019-06-13
$ alias paste.exe='powershell.exe Get-Clipboard'
$ echo "world" | clip.exe
$ paste.exe
world
source: https://github.com/Microsoft/WSL/issues/1069#issuecomment-391968532
Alias
Here is a helpful alias from @Gordan Bean that removes the \r\n
:
alias paste.exe="powershell.exe Get-Clipboard | perl -p -e 's/\r\n$//'"
来源:https://stackoverflow.com/questions/55974462/pipe-from-clipboard-in-linux-subsytem-for-windows