First line of batch file fails - is not recognized as an internal or external command, operable program or batch file

Scott Software picture Scott Software · Mar 4, 2014 · Viewed 11.9k times · Source

on Windows 7 in VS2012, I have setup an External Tool to call a bat file (let’s call it BatA.bat). In the external tool, I am passing in $(ItemDir) as the one and only Argument and I have the Initial Directory to $(ItemDir) as well.

Within BatA.bat, a call is made to run BatB.bat like this:

call "%1BatB.bat"

This command calling BatB.bat results in the following in the output window:

'rem' is not recognized as an internal or external command, operable program or batch file.

hello

BatB.bat has the following code:

rem ***Bat B***
@echo off
echo.
echo hello

The odd thing is that in spite of the error message, BatB.bat does run and executes perfectly!

I just can’t figure out why I’m getting the error message on the call to BatB.bat in the first place...

BatA.bat and BatB.bat are both in the same directory. I’ve tried hard coding the path in the call to BatB.bat as well as doing a cd to the bat directory before calling BatB.bat but I still receive the same error.

Answer

Steven picture Steven · Jun 25, 2014

Easiest way to fix this for me was to open the file in notepad++ and under the Encoding tab, make sure to use an encoding that has no BOM at the end.

It is the BOM that causes 'rem' is not recognized as an internal or external command.......