windows my.bat 未被识别为内部或外部命令、可运行的程序或批处理文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8320648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
my.bat not recognized as an internal or external command, operable program or batch file
提问by John Adams
When I logon to this Windows 2008 R2 Server and launch a CMD window, the default directory is:
当我登录到此 Windows 2008 R2 Server 并启动 CMD 窗口时,默认目录为:
C:\Users\SVC_asl2trim>
So I added this to the PATH and then I issued:
所以我把它添加到了 PATH 中,然后我发出了:
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:
我在上面的那个目录中有一个小的 .bat 文件,但我不断收到:
my.bat not recognized as an internal or external command, operable program or batch file
my.bat 未被识别为内部或外部命令、可运行的程序或批处理文件
This is maddening. I do this so infrequently .... I know there is some trick I am forgetting.
这令人抓狂。我很少这样做......我知道我忘记了一些技巧。
回答by John Adams
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.txtto my.batbut the problem was that it was actually named my.bat.txt! Fixing that was key to this problem.
应该归功于 Dennis 验证 my.bat 应该可以工作,但正如他推测的那样,它没有被命名。我以为我已经正确地将它从my.txt重命名为my.bat但问题是它实际上被命名为my.bat.txt!解决这个问题是解决这个问题的关键。
回答by unqualified
I was getting this error because my batch file was not ascii encoded; it was utf-8.
我收到这个错误是因为我的批处理文件不是 ascii 编码的;它是 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.
由于 UTF 和 UCS 通常在文件的开头包含 BOM,因此请确保将其保存为 ASCII 或 UTF-8 而不包含 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.
如果您确实需要替代编码,则有时可以将第一行设为空白(对我而言,UTF-8 BOM 不会停止执行,但 USC-2 会停止)。两者都会从第一行打印错误消息,因此这不是理想的解决方案。