DOS – Batch – Error – “was unexpected at this time”

Background

Let us pull in real quick and talk about a DOS ditch that is easy to get ensnared in.

 

DOS-Batch

Original

Code


rem display version number
ver

rem Adding Comments
rem https://www.nobody.com/?a=1

IF %ERRORLEVEL% NEQ 0 Echo errorlevel is %ERRORLEVEL%


Output

Output – Image

Output – Text

>specialChars.original.cmd

>rem display version number

>ver

Microsoft Windows [Version 10.0.17763.2686]

>rem Adding Comments
1 was unexpected at this time.

>rem https://www.nobody.com/?a=1

>

Revision

Outline

  1. The error is due to the presence of the ? in the rem statement
  2. We have to escape the question ( ? ) mark
  3. We escape the question mark by placing the \ ahead of it ( ? )

Code


rem display version number
ver

rem Adding Comments
rem escape the special character ?
rem original ?
rem revised  \?
rem https://www.nobody.com/\?a=1

IF %ERRORLEVEL% NEQ 0 Echo errorlevel is %ERRORLEVEL%

Output

Output – Image

Output – Text

>specialChars.revised.cmd

>rem display version number

>ver

Microsoft Windows [Version 10.0.17763.2686]

>rem Adding Comments

>rem escape the special character ?

>rem original ?

>rem revised  \?

>rem https://www.nobody.com/\?a=1

>IF 0 NEQ 0 Echo errorlevel is 0

>

Dedication

Always in dedication to my Bro, Gerald S.

Shared a working cube with him years ago.

That IVY League education goes a long way.

 

Source Code

GitHub

Gist

DanielAdeniji/dos.batch.remarkStatement.specialChars.original.cmd

Link

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

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