Copy a whole text into clipboard

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
russs
Posts: 3
Joined: 29 Nov 2010 05:15

Copy a whole text into clipboard

#1 Post by russs » 10 Oct 2011 07:00

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 :)

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Copy a whole text into clipboard

#2 Post by dbenham » 10 Oct 2011 11:54

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

russs
Posts: 3
Joined: 29 Nov 2010 05:15

Re: Copy a whole text into clipboard

#3 Post by russs » 12 Oct 2011 04:14

Thank you Dave, that worked ! :D

Post Reply