6
votes

When I logon to this Windows 2008 R2 Server and launch a CMD window, the default directory is:

C:\Users\SVC_asl2trim>

So I added this to the PATH and then I issued:

C:\Users\SVC_asl2trim>set path
Path=C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32
\WindowsPowerShell\v1.0\;D:\Program Files\Hewlett-Packard\HP TRIM\;C:\Users\SVC_
asl2trim\
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

C:\Users\SVC_asl2trim>

I have a small .bat file in that directory above but I keep getting:

my.bat not recognized as an internal or external command, operable program or batch file

This is maddening. I do this so infrequently .... I know there is some trick I am forgetting.

2
Can you print the content of the directory above so that we can verify the batch file is indeed in that directory? Use dir /b > list.txt - ee.
Are you sure your batch file is called my.bat? Because if it is, this should work... - Dennis
Gosh, you are right. File is actually my.bat.txt !! Changing it properly fixed it. Thank you. - John Adams
How did you add it to PATH? Where are you trying to execute my.bat? The environment is different per process and user. - kichik
please close this question, or post your solution and accept it. Good luck. - shellter

2 Answers

9
votes

My stupid mistake...

Credit should go to Dennis for verifying that my.bat should work but as he surmised, it was not named that. I thought I had renamed it correctly from my.txt to my.bat but the problem was that it was actually named my.bat.txt ! Fixing that was key to this problem.

4
votes

I was getting this error because my batch file was not ascii encoded; it was utf-8.

Since UTF and UCS often contain a BOM at the start of the file, make sure to save it as ASCII or UTF-8 without the BOM.

If you really need an alternate encoding, making the first line blank can sometimes work (for me the UTF-8 BOM doesn't stop execution, but the USC-2 one does). Both will print an error message from the first line, so it's not an ideal solution.