Pipe from clipboard in linux subsytem for windows

爱⌒轻易说出口 提交于 2019-12-11 00:56:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!