Escape Characters in Windows’ CMD.EXE

I’m currently working with another developer on how to get random windows shell commands that are stored in a database to actually execute properly on a target system.  The idea is that we’ll Start() a new Process object, and execute the command as arguments.

Check out this screenshot:

Windows Command Shell

What we’re doing here is running the local ECHO command; which  will write out another ECHO command to a batch file which we can then execute.  A couple neat things which may help you:

The caret (^) character is an escape character for things like <, >, (, ), etc.    These are special shell characters.

You can quote the whole string.

I hope this helps the random Google searcher who arrives here.


6 Responses to “Escape Characters in Windows’ CMD.EXE”

  1. 1 Jakub Lucký April 27, 2008 at 10:38 pm

    “I hope this helps the random Google searcher who arrives here.”

    Sure it does 😉

  2. 2 Tabor May 12, 2008 at 4:26 pm

    It sure does help.

  3. 3 Jon July 19, 2008 at 10:59 am

    Does indeed. I tried every combination of forward and backslashes imaginable. A caret? Heh.

  4. 4 Random User July 22, 2008 at 11:53 pm

    Hi, thank you!

    I just want to confirm your wish… thank you again ^_^

  5. 5 Inceva August 20, 2008 at 9:33 am

    I alot have tried every combination of forward and backslashes imaginable. Thank you so much for posting. If you ever need any help on a web project hit me up on


  6. 6 Wyrd September 11, 2008 at 9:36 am

    Yes, it does help. *Thank you*.

    The thing is, I think I knew this once, but then I forgot it.

    But what I was really trying to do still doesn’t seem to work.

    I was trying to take output like this:
    ping -n 1 | find “Reply” > 1pingout

    then I wanted to set the window title equal to the result of that ping.

    The way I tried doing it was:
    set /p MYTITLE= < 1pingout
    title %MYTITLE%

    This fails whenever MYTITLE contains a “<“, which it sometimes does if the ping return time was really small.

    Even with all the new options in set, I can’t see any way of escaping the “<” without using something Unixie.

    Furry cows moo and decompress.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

TwitterCounter for @anthonyrstevens
Add to Technorati Favorites

RSS Feed

View Anthony Stevens's profile on LinkedIn

%d bloggers like this: