windows linux子系统中剪贴板中的管道

Gor*_*ean 10 clipboard windows-subsystem-for-linux

使用适用于 Windows 的 Linux 子系统 (LSW),clip.exe可用于将数据复制到 Windows 剪贴板:

$ 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.
Run Code Online (Sandbox Code Playgroud)

有没有办法剪贴板管道?预期用途示例:

$ paste.exe > foo.txt

$ paste.exe | tr , '\n' | clip.exe
Run Code Online (Sandbox Code Playgroud)

Non*_*uit 13

解决方案

这会将 Windows 的剪贴板打印到标准输出:

powershell.exe Get-Clipboard
Run Code Online (Sandbox Code Playgroud)

例子

$ echo "hello" | clip.exe
$ powershell.exe Get-Clipboard
hello

Run Code Online (Sandbox Code Playgroud)
$ date +%Y-%m-%d | clip.exe
$ powershell.exe Get-Clipboard
2019-06-13

Run Code Online (Sandbox Code Playgroud)
$ alias paste.exe='powershell.exe Get-Clipboard'
$ echo "world" | clip.exe
$ paste.exe
world

Run Code Online (Sandbox Code Playgroud)

来源:https : //github.com/Microsoft/WSL/issues/1069#issuecomment-391968532

  • 干得好@NonlinearFruit!我看到在我的 WSL/Windows 版本中,`Get-Clipboard` 将 `\r\n` 附加到内容的末尾。我使用以下作为我的别名来修剪这些不需要的添加:`alias paste.exe="powershell.exe Get-Clipboard | perl -p -e 's/\r\n$//'"` (4认同)