How to pipe text from command line to the clipboard
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Hypnotic Orient Looping
--
Chapters
00:00 How To Pipe Text From Command Line To The Clipboard
00:18 Answer 1 Score 6
00:35 Accepted Answer Score 38
00:56 Answer 3 Score 21
01:36 Answer 4 Score 6
02:29 Thank you
--
Full question
https://superuser.com/questions/97762/ho...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #windows #macos #commandline #clipboard
#avk47
ACCEPTED ANSWER
Score 38
I don't believe so - Vista (or NT4) introduced the clip
tool, which would do your command as dir | clip
- but there's nothing on XP. If you're willing to use 3rd party applications, though, there's this, which works as above, except is called cb
, not clip.
ANSWER 2
Score 21
For Windows and non-Windows, this post (dead link) used to say:
On Windows Vista or later, try:
echo hello | clip
On Linux, try:
echo hello | xclip
On Mac OS X, try:
echo hello | pbcopy
For example, you might do
(cat myFile.txt | xclip)
. This would basically allow you to edit the clipboard directly.
(I came here via Google looking for the Mac equivalent of xclip
)
Similarly for contents of files (as you don't cat
on windows):
type filename | clip % OR clip < filename %windows cat filename | xclip # OR xclip < filename # X11 / Unix / Linux cat filename | pbcopy # OR pbcopy < filename # MacOS X
ANSWER 3
Score 6
There's no standard way, but you can apparently use clip.exe
which came with the Windows Server 2003 resource kit . Source
The problem now becomes getting hold of a legal copy of this.
ANSWER 4
Score 6
I looked into this for myself earlier today. Below is something helpful to those wanting to insert and retrieve information from the clipboard in a linux distribution. Below that is something that could prove helpful for those with windows.
Linux
By default, xclip uses the "primary" clipboard, which is what you have copied with your mouse. To get it to use the manual copy clipboard, use xclip -sel clip instead.
comment #3 here:
http://ubuntuforums.org/showthread.php?t=413786
Windows
The functionality is available in Active Perl distribution also, which is what I wound up using on the windows box in this exercise; The windows clip.exe didn't appear to allow for reading the data from the clipboard (only writing into clipboard).