[英]Error with bat file token or for loop: not recognized as an internal or external command, operable program or batch file
Need Windows .bat file tech support. 需要Windows .bat文件技术支持。 I am having trouble running Win 7 bat files which loop through tokens and variables. 我在运行通过令牌和变量循环的Win 7 bat文件时遇到问题。 The script below works on my wifes PC, and should on all PCs, but does not on mine. 以下脚本可在我妻子的PC上使用,并且应在所有PC上使用,但不适用于我的PC。
** I am running Windows 7 in VMWare off my Mac. **我在Mac上的VMWare中运行Windows 7。
The file is located at the root of c: 该文件位于c的根目录:
This short little script, and any others like it with tokens gives me errors ( I copied the script below out of the .bat file ): 这个简短的小脚本以及其他带有令牌的脚本给我带来了错误(我从.bat文件中复制了以下脚本):
setLocal ENABLEDELAYEDEXPANSION
set SCHEMA_one= first
set SCHEMA_two= second
set SCHEMA_three= third
@ECHO ON
FOR /F "tokens=2* delims=_=" %%A IN ('set SCHEMA_') DO (
echo "looping through " %%A
)
endLocal
I get the following error: 我收到以下错误:
C:\>FOR /F "tokens=2* delims=_=" %A IN ('set SCHEMA_') DO (echo "looping through " %A )
'set SCHEMA_' is not recognized as an internal or external command, operable program or batch file.
Ideas??? 想法???
Many thanks in advance. 提前谢谢了。 I have been stuck for hours and hours... 我被困了几个小时...
You may need to look into for /?
您可能需要寻找for /?
, specifically the use of usebackq
. ,特别是usebackq
的使用。 This can change the interpretation of you set. 这可以更改您设置的解释。
Additionally, I always use enableextensions
in my setlocal
command as well, to ensure the environment is set up exactly as I need. 另外,我也总是在setlocal
命令中使用enableextensions
,以确保完全按照我的需要设置环境。
The other thing is to do a hex dump of your batch file to make sure that the character between set
and SCHEMA
is actually a space. 另一件事是对批处理文件进行十六进制转储,以确保set
和SCHEMA
之间的字符实际上是一个空格。 If it's a different character, then cmd
will probably treat set.SCHEMA
(where the .
is that funny character) as one command. 如果它是一个不同的字符,则cmd
可能set.SCHEMA
(其中的.
是那个有趣的字符)视为一个命令。
EDIT- I DID find the answer.. Complete user error.. 编辑-我找到了答案。完整的用户错误..
At some point, the COMSPEC environment variable path got changed, and so was WRONG!!!! 在某个时候,COMSPEC环境变量路径已更改,因此WRONG !!!! With a typo!!! 有错字!!! :/ So lame. :/好la脚。
While comparing env variables between my new environment and old, I finally noticed the typo. 在比较新环境和旧环境之间的env变量时,我终于注意到了错字。 Man, one character cost me hours and hours. 伙计,一个字符花了我几个小时。 I didn't realize before ( though its obvious now ) that was the path used for the bat command or I would have given it more scruteny. 我以前没有意识到(尽管现在很明显),这是蝙蝠命令所使用的路径,否则我会更加谨慎。 Not sure why it worked at all (???) 不确定为什么它可以工作(???)
================ Well, I am not happy with the fix- because it was a BIG hammer. ===============好吧,我对修复不满意-因为它是一把大锤子。 But I installed a new Windows 7 VM, and now I can run the script. 但是我安装了新的Windows 7 VM,现在可以运行脚本了。 Earlier In stalled a newer version of the vm- 3.1.4 ( the newest free upgrade from my 3.1.2 ) and that did not solve the problem. 早期的In拖延了vm-3.1.4的较新版本(这是我的3.1.2的最新免费升级),但并没有解决问题。 And before that I tried the things suggested above ( Many thanks to the people who posted above! ) 在此之前,我尝试了上述建议(非常感谢上面发布的人员!)
Not sure what is screwed up with my windows install, but it's something.. I've compared against other computers, and my environment args all look good. 不知道我的Windows安装搞砸了什么,但这是什么。.我已经与其他计算机进行了比较,我的环境参数看起来都不错。 Java is good, etc. Just something about either my user account on that VM, or ...? Java是好的,等等。关于我在该VM上的用户帐户,还是...? Not sure. 不确定。 Ran out of time, had to move on. 跑出时间,只好继续前进。 :) :)
If I figure it out I will post the answer. 如果我知道了,我将发布答案。 In the mean time I'll be setting up and hopefully working from this new VM. 同时,我将进行设置并希望使用该新VM。
cheers! 干杯! Dustin 达斯汀
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.