Solved Strange batch file behaviour

Various / CUSTOM BUILT
December 8, 2015 at 18:19:34
Specs: Windows 10, Intel i7 4770k, 16GB 1600MHz RAM
I have this simple batch file:
@Echo off
setlocal enabledelayedexpansion
Echo test
pause > nul
endlocal
exit

But when I run it, this happens:
http://prntscr.com/9bzgz3

Why? Is there like an invisible character before the @Echo off part? Wrong encoding? I am clueless...

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ


See More: Strange batch file behaviour

Report •

✔ Best Answer
December 9, 2015 at 19:09:11
UTF and Unicode seem to be the new "standard" (vs ASCII). Anymore, when batch or cmd fails, that's the first thing I look for. Fixing it is easy - it's figuring out the diagnosis that can drive you 'round the bend'. I suggest using some form of an editor that will show the file's format, such as EDIT or DEBUG. PS: forget DEBUG for 64-bit.


#1
December 8, 2015 at 19:17:08
the exact copy of your code works on my windows 2000 sp4 and windows xp sp2. maybe Windows 10 doesnt support it. and by course of evolution, dos commands are getting almost extinct. might be the reason why it didnt work.

Report •

#2
December 8, 2015 at 20:02:20
I doubt that is the issue, I work with batch files on my computer on a daily basis, all behave as expected, except this one.

Also, DOS may almost be extinct, but batch is sligthly different and modernized while also having some commands from DOS, but it's not going to go extinct just yet and will most likely be supported for quite a while.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ


Report •

#3
December 8, 2015 at 20:30:03
then how come the code worked for me?

Report •

Related Solutions

#4
December 8, 2015 at 21:05:35
Solved the issue.

Was using UTF-8 encoding, which puts an invisible "Byte Order Mark" to the beginning of the file, which cmd.exe didn't know how to interpret, so it resulted in it messing up the @Echo off command.

The reason it worked for you is most likely because you pasted the code in a file that used ANSI encoding or something similiar, which doesn't use Byte Order Marks.

Don't worry if plan A fails, there are 25 more letters in the alphabet ;)

message edited by RainBawZ


Report •

#5
December 9, 2015 at 00:11:03
yeah right, byte order marks. complex terms for simple batch programming lol

Report •

#6
December 9, 2015 at 17:20:45
I was gonna say I use batch with old dos commands daily. Don't think they are unusable at all.

::mike


Report •

#7
December 9, 2015 at 19:09:11
✔ Best Answer
UTF and Unicode seem to be the new "standard" (vs ASCII). Anymore, when batch or cmd fails, that's the first thing I look for. Fixing it is easy - it's figuring out the diagnosis that can drive you 'round the bend'. I suggest using some form of an editor that will show the file's format, such as EDIT or DEBUG. PS: forget DEBUG for 64-bit.

Report •

Ask Question