views:

1297

answers:

4

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.

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
A: 

I'm guessing that %CHANGES% is not in the correct format/structure for the loop so the DO cannot be executed. Add the following line before the loop to check you're getting what you expected from the SET CHANGES command;

ECHO %CHANGES%

If the assignment is more batch code to execute you might need to use CALL. What are you passing in when calling the batch file for %1 and %2?

Dave Anderson
Another program actually is supposed to call this batch file and pass a directory and an integer value. I added code to echo the %1 when I tested the batch file myself and passed values to it, the batch code echoed blanks indicating that the passed arguments were NOT assigned, i.e. post-commit.bat file:///d:/repos 10Any idea why the arguments are not being assigned?
@Dan Is it really as easy as @Binary Worrier points out?
Dave Anderson
@Dave Anderson: Binary Worrier's suggestion is on the right track, but not quite complete; the code needs the "usebackq" option and back ticks.
A: 

can you try to run it without the REM Statement. Comments sometimes make things work differently.

Anirudh Goel
+5  A: 
FOR /f %%a IN %CHANGES% DO svn update %%a

should be

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

Hope this helps,

Binary Worrier
A: 

After modifying my original code I've got it to 'work.' The svnlook command returns for example: trunk\images\smileyface.jpg

Currently, the for loop returns only the 'U' rather than the 'smileyface.jpg' which I want. 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)