3

I have a batch file that contains this code:

del /F /S /Q /A "debug.properties"
del /F /S /Q /A "context/security/preauth/projectid-source/header/projectid-source.xml"
del /F /S /Q /A "context/compatibility/readme.txt"
del /F /S /Q /A "archived_logs"
del /F /S /Q /A "ai-license-add-in-IrsProjectManagement.bin"
del /F /S /Q /A "context/security/preauth/projectid-source/header/projectid-source.properties"
del /F /S /Q /A "debug.properties.DSPROD"
del /F /S /Q /A "context/security/preauth/projectid-source/header"

When I execute the batch from the command line I get the error: " 'd' is not recognized as an internal or external command, operable program or batch file"

It works fine when I execute the del statement directly from the command line.

Any ideas what's going on here?

user2135970
  • 795
  • 2
  • 9
  • 22
  • Which line gives you the error? What's the name of your batch file? – Laf Dec 11 '14 at 16:03
  • The name of the file is test_1b.bat and the error takes place on the first line of the file. When I comment out the first line (REM) I get the message "'R' is not recognized as an internal or external command ...' – user2135970 Dec 11 '14 at 16:14
  • 2
    Funny behavior. Check this [question](http://stackoverflow.com/questions/22159534/), does it help you fix your problem? – Laf Dec 11 '14 at 16:16
  • What editor are you using to create the batch file? This sounds like a Unicode issue. Can you try the following `type test_1b.bat > test_1b_ascii.bat` and see if the new batch file works? – Ryan Bemrose Dec 11 '14 at 21:29

1 Answers1

1

The batch file is obviously saved as UTF-16 little-endian encoded file without a byte order mark (BOM).

Text editors usually indicate the encoding of a file somewhere. For example text editor UltraEdit indicates the encoding for active file at bottom in status bar.

This batch file UTF-16 encoded without BOM starts in binary with the bytes

00000000h: 64 00 65 00 6C 00 20 00 2F 00 46 00 20 00 2F 00 ; d.e.l. ./.F. ./.
00000010h: 53 00 20 00 2F 00 51 00 20 00 2F 00 41 00 20 00 ; S. ./.Q. ./.A. .
00000020h: 22 00 64 00 65 00 62 00 75 00 67 00 2E 00 70 00 ; ".d.e.b.u.g...p.
00000030h: 72 00 6F 00 70 00 65 00 72 00 74 00 69 00 65 00 ; r.o.p.e.r.t.i.e.
00000040h: 73 00 22 00 0D 00 0A                            ; s."....

As the NULL byte is interpreted as end of string by cmd.exe, the command to run is just d which is an unknown command.

Convert the file from UTF-16 to ASCII in text editor (option on Save As) or with

type test_1b.bat > test_1b_ascii.bat

as suggested by Ryan Bemrose and the batch file will start working.

Batch files are usually in North American and Western European countries "ASCII" files using an OEM code page like code page 850 (OEM multilingual Latin I) or code page 437 (OEM US) and not code page Windows-1252 as used usually for single byte encoded text files. The code page to use for a batch file depends on local settings for non Unicode files in console. The code page does not matter if just characters with a code value smaller 128 are used in batch file, i.e. the batch file is a real ASCII file.

Community
  • 1
  • 1
Mofi
  • 46,139
  • 17
  • 80
  • 143