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

荒凉一梦 提交于 2019-12-21 11:02:15

问题


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.


回答1:


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.......



来源:https://stackoverflow.com/questions/22159534/first-line-of-batch-file-fails-is-not-recognized-as-an-internal-or-external-co

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!