If a file that you want to parse has command control characters, like an HTML file, the CMD.EXE processor will treat
these characters as controls, causing your script to malfunction.
The ! % ^ & | " characters have special meaning to the CMD.EXE processor, as well as the = ; ( ) , : ' characters, when used in various combinations.
Your script is also NOT able to detect TAB characters.
I have scripted RepCmdCtrl.bat to allow a batch job to process a file that contains command control characters, by replacing the command control characters, per the following table:
Control Character | ! | % | ^ | & | | | > | " | = | ; | ( | ) | , | : | ' | TAB | |
Resulting Character | ¡ | ¥ | Þ | ¦ | ü | ¼ | ¾ | ¢ | ½ | » | ¨ | © | ¬ | º | ± | « |
Keystrokes (Numeric Keypad) ALT+ |
0161 | 0165 | 0222 | 0166 | 0252 | 0188 | 0190 | 0162 | 0189 | 0187 | 0168 | 0169 | 0172 | 0186 | 0177 | 0171 |
The syntax for using RepCmdCtrl.bat is:
for /f "Tokens=1* Delims=:" %%a in ('call RepCmdCtrl iFile') do ( set line=%%b call :DoSomething ) ... goto :EOF :DoSomething ... ...Where: iFile is the fully qualified file name of the input file that contains the command Control Characters.
NOTE: For an alternate method, see How can a batch job process files that contain command control and TAB characters?
RepCmdCtrl.bat contains:
@echo off if \{%1\}==\{\} @echo Syntax RepCmdCtrl iFile&goto :EOF if exist "%TEMP%\RepCmdCtrl.VBS" goto doit @echo dim iString, oString, objArgument, fso, iFile, rFile>"%TEMP%\RepCmdCtrl.VBS" @echo Set objArgument = Wscript.Arguments>>"%TEMP%\RepCmdCtrl.VBS" @echo iFile=objArgument(0)>>"%TEMP%\RepCmdCtrl.VBS" @echo set fso = CreateObject("Scripting.FileSystemObject")>>"%TEMP%\RepCmdCtrl.VBS" @echo set rfile = fso.OpenTextFile(iFile, 1, false)>>"%TEMP%\RepCmdCtrl.VBS" @echo Do until rFile.AtEndOfStream = True>>"%TEMP%\RepCmdCtrl.VBS" @echo iString = rFile.ReadLine>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(iString, vbtab, "«")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, "!", "¡")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, "%%", "¥")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, "^", "Þ")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, "&", "¦")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, "|", "ü")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, ">"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, ">", "¾")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, """", "¢")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, "=", "½")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, ";", "»")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, "(", "¨")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, ")", "©")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, ",", "¬")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, ":", "º")>>"%TEMP%\RepCmdCtrl.VBS" @echo oString = Replace(oString, "'", "±")>>"%TEMP%\RepCmdCtrl.VBS" @echo Wscript.echo "*:" ^& oString>>"%TEMP%\RepCmdCtrl.VBS" @echo loop>>"%TEMP%\RepCmdCtrl.VBS" @echo rFile.close>>"%TEMP%\RepCmdCtrl.VBS" :doit cscript //NOLOGO "%TEMP%\RepCmdCtrl.VBS" %1