简体   繁体   English

循环语句的批处理文件

[英]Batch file for loop statement

I've put together the batch file below; 我将下面的批处理文件放在一起; I don't have much experience with batch files and I can't figure out why the file fails with an error message stating that the: 我对批处理文件没有太多的经验,也无法弄清楚为什么文件失败并显示一条错误消息,指出:

DO command was unexpected. DO命令是意外的。

Looking at the following code, does anyone know what I did wrong? 看下面的代码,有人知道我做错了吗? Thanks. 谢谢。

@ECHO OFF
REM Set arguments supplied by Subversion 
SET REPOS = %1
SET REV = %2

REM Set working directory path 
SET WORKSPACE = D:\apache\htdocs

REM Assign changes to variable 
SET CHANGES = svnlook changed %REPOS% -r %REV% 

REM Update only changed files  
FOR /f %%a IN %CHANGES% DO svn update %%a
FOR /f %%a IN %CHANGES% DO svn update %%a

should be 应该

FOR /f %%a IN (%CHANGES%) DO svn update %%a

Hope this helps, 希望这可以帮助,

I'm guessing that %CHANGES% is not in the correct format/structure for the loop so the DO cannot be executed. 我猜测%CHANGES%的循环格式/结构不正确,因此无法执行DO Add the following line before the loop to check you're getting what you expected from the SET CHANGES command; 在循环之前添加以下行,以检查您是否从SET CHANGES命令中获得了期望的结果;

ECHO %CHANGES%

If the assignment is more batch code to execute you might need to use CALL . 如果分配的批处理代码较多,则可能需要使用CALL What are you passing in when calling the batch file for %1 and %2 ? 调用%1%2的批处理文件时传递的是什么?

can you try to run it without the REM Statement. 您可以尝试在没有REM语句的情况下运行它吗? Comments sometimes make things work differently. 注释有时会使事情有所不同。

After modifying my original code I've got it to 'work.' 修改完原始代码后,我就可以正常工作了。 The svnlook command returns for example: trunk\\images\\smileyface.jpg svnlook命令返回例如:trunk \\ images \\ smileyface.jpg

Currently, the for loop returns only the 'U' rather than the 'smileyface.jpg' which I want. 当前,for循环仅返回我想要的“ U”而不是“ smileyface.jpg”。 So, while the code now works, it does function yet how I'd like (still working on it). 因此,尽管代码现在可以工作,但它确实可以按我的意愿运行(仍在工作)。

Below is the revamped code (Note: I had to remove all spaces between my variables and their assigned values). 下面是经过修改的代码(注意:我必须删除变量及其分配的值之间的所有空格)。

@ECHO OFF
REM Set arguments supplied by Subversion 
SET REPOS=%1
SET REV=%2

REM Set working directory path 
SET WORKSPACE=D:\apache\htdocs

REM Assign changes to variable 
SET CHANGES=svnlook changed %REPOS% -r %REV% 

REM Update only changed files  
FOR /F "usebackq" %%a IN (`%CHANGES%`) DO (svn update %%a)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM