Using the clip utility with special characters

jrmcanada2 used Ask the Experts™
I'm trying to copy text to the clipboard from the command line. If I try something simple like:

ECHO test | CLIP

it works fine and puts the word test in the clipboard. My problem is that I have a special character (specifically an ampersand) in the text I want to copy and it makes the clip utility choke:


If I try the same text without the ampersand, it works fine so I know it's the ampersand that is causing the problem.

I tried using quotation marks like this:


That gets rid of the error but the quotation marks get copied to the clipboard, too.

Any ideas?

Thanks in advance.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Test your restores, not your backups...
Top Expert 2016
Yes, the ampersand (&) is a special operator in a command line to join two commands together.

Normally special characters can be escaped by preceding with a caret (^) but the ampersand doesn't always like that.

In your specific case preceding it with three  carets seems to get the job done.  Gotta love the DOS command line...

Notice that I would also remove the trailing space from the string you are piping to CLIP, as everything before the pipe will be sent to CLIP, including any trailing spaces.  You probably don't need/want that trailing space, so do as follows.


Open in new window



Thank you! It would have been a LONG time before I figured that out on my own. :)

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial