Copy to and Paste from Clipboard: A cross-platform solution in Java
By Angsuman Chakraborty, Gaea News NetworkMonday, November 1, 2004
Have you ever felt the need for copying an output generated on command line to clipboard, or wanted to paste from clipboard to command line?
The following java utilities (cross-platform) will help you do just that.
Usage:
=> To copy the output of a program to clipboard
echo Hello World | java ClipCopy
dir | java ClipCopy
=> To paste the clipboard contents to a file
java ClipPaste > clip.txt
This can also be used to remove the requirement to create temporary files in a complex batch/shell script.
To type clipboard contents directly from command line just type: java ClipCopy
End with content with end character of your OS, Ctrl-Z for windows & Ctrl-D for Unix.
Download:
ClipCopy.class
ClipPaste.class
For line counters, ClipCopy is 4 lines of code and ClipPaste is 2 lines of code. This doesn’t take into account the import, class & main declarations and opening & closing braces.
Let me know if you find this useful.
Note: For non-Java users you might find it easier to download the jar file and run the modified commands as shown below:
Usage:
=> To copy the output of a program to clipboard
echo Hello World | java -cp clip.jar ClipCopy
dir | java -cp clip.jar ClipCopy
=> To paste the clipboard contents to a file
java -cp clip.jar ClipPaste > clip.txt
This takes care of any classpath setting issue. You still need to have jre installed in your system.
Limitation: Not tested with binary content. This is meant for text transfers only.
April 10, 2009: 3:11 am
Fetch the page using URLConnection in Java and then post the code using any CVS (who uses cvs anymore?) Java API. |
![]() mahesh |
April 9, 2009: 4:42 pm
i want to fetch output from jsp page and paste it to the file in cvs repository automatically ( using some code ie. not manual copy-paste.) this all is going to be done in eclipse ide. how can i get this code?? Thank u. |
March 20, 2009: 3:10 pm
[...] it in Internet Explorer and copy it to clipboard using Ctrl-A Ctrl-C after first clicking within the explorer. Now the HTML is copied in proper [...] |
![]() Pete |
![]() Pete |
October 2, 2006: 12:21 am
I am having a problem with this application… it works well with “| java -cp clip.jar ClipCopy” piped from another command, but the problem is that it inserts a carriage return after the clipboard contents. Any thoughts on how to get around this? Cheers, Pete |
![]() Anjan Bacchu |
July 28, 2005: 1:24 pm
hi there, thank you. I’ve previously managed something like this using perl My perl script suffers though from not being able to copy multi-line output properly. I use the clipboard copy script using something like this But… coming back to your program, on Windows XP, BTW, I am using cygwin Thank you, BR, |
March 15, 2005: 4:38 pm
[...] ve it. Remember to set Save as Type to HTML . Open it in Internet Explorer and copy it to clipboard using Ctrl-A Ctrl-C afte [...] |
Angsuman Chakraborty