Gordon Bean
Gordon Bean

Reputation: 4612

Pipe from clipboard in linux subsytem for windows

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

Upvotes: 17

Views: 3864

Answers (1)

NonlinearFruit
NonlinearFruit

Reputation: 2579

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

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

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

Upvotes: 27

Related Questions