【问题标题】:Pipe from clipboard in linux subsytem for windows来自 Windows 的 linux 子系统中剪贴板的管道
【发布时间】:2019-09-22 06:36:04
【问题描述】:

使用 Linux Subsystem for Windows (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.

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

$ paste.exe > foo.txt

$ paste.exe | tr , '\n' | clip.exe

【问题讨论】:

标签: clipboard windows-subsystem-for-linux


【解决方案1】:

解决方案

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

powershell.exe Get-Clipboard

示例

$ 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

paste() {  # Add me to your .bashrc, perhaps.
    powershell.exe Get-Clipboard | sed 's/\r//'
    # The `sed` will remove the unwelcome carriage-returns
}

来源: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$//'"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-11-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多