Quick-Tip: Escaping special characters in MS-DOS

The other day I needed to make a batch file, and encountered the problem of having characters (specifically spaces and parentheses), which needed to be escaped in order for the batch file to run correctly in MS-DOS.

An example of this problem would be having the following line in a batch file:

Incorrect example: C:\Program Files (x86)\Program\executableFile.exe

This example would result in an error stating:

’C:\Program’ is not recognized as an internal or external command, operable program or batch file.

This error is caused by multiple special characters which were not escaped. To solve this problem a ‘^’ should be placed before all characters which need to be escaped (eg. spaces, parentheses, etc). See the correct example below:

Correct example: C:\Program^ Files^ ^(x86^)\Program\executableFile.exe

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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