Page 1 of 1

Copy a whole text into clipboard

Posted: 10 Oct 2011 07:00
by russs
Hello,

I want to copy a whole text (with many lines) into clipboard.

I have succeeded to copy a 1-line text with the following batch:

Code: Select all

echo my text | clip


This puts "my text" into the clipboard, the problem is I want a much longer text (a paragraph with many lines) to be copied to the clipboard, can you please help ?

Thank you in advance :)

Re: Copy a whole text into clipboard

Posted: 10 Oct 2011 11:54
by dbenham
Presumably you have multiple lines of code that generate the text. You just need to make sure that all of the text that is to be captured is directed to the clipboard with the same pipe.

This is trivial if you have a batch file that generates the text. Simply call the batch file and pipe the output

Code: Select all

mybatch|clip


If you want to capture the output of some block of code within a batch file, just enclose the block in parentheses:

Code: Select all

(
  echo line1
  echo line2
)|clip

Bear in mind that if you use variable expansion and the variable is set within the block, then you will need to use delayed expansion because the entire block will be expanded prior to any execution if you use normal % expansion.


Dave Benham

Re: Copy a whole text into clipboard

Posted: 12 Oct 2011 04:14
by russs
Thank you Dave, that worked ! :D