I believe I am using the commands correctly, but the clipboard is empty using the following:

C:\Windows\System32\cmd.exe /c echo 28376^>1847|clip

I believe the problem is the > which I am using, and I use the ^ escape character to override.

Any suggestion as to what is wrong?

1 Answer 1


What is wrong?

the clipboard is empty using the following:

echo 28376^>1847|clip

The reason it doesn't work as expected is:

When piping or redirecting text, applying an escape character gets a little more complex, a pipe will start two new cmd.exe instances, each of these cmd processes are passed one side of the pipe and will parse their part once again (with the cmd-line parser, not with the batch-line-parser).

Source: Quotes, Escape Characters, Delimiters - Windows CMD - SS64.com

So you need extra escape characters:

echo 28376^^^>1847|clip

Now, the first caret escapes the second caret ^, the third caret escapes the > so now the new cmd instance inherits >&

Further Reading: batch file - Why does delayed expansion fail when inside a piped block of code? - Stack Overflow

  • 1
    Interesting didn't know cmd would act like this when piping... Aug 8 at 10:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.