Problem running SVN copy from Batch file FOR loop
I have a loop in a .BAT file which does the following, as a开发者_如何学Python quick hack to let me branch projects (input checking, etc left out, this is the command which gets run):
@for %%X in (%~3) do svn copy ^
https://my.svn.account/%%X/trunk ^
"https://my.svn.account/%%X/branches/%~1" ^
-m "%~2"
So you use it like:
branchTool test_branch "testing branch tool" "proj1,proj2"
The SVN commands look right:
>branchTool.bat test_branch "testing branch tool" "proj1,proj2"
svn copy https://my.svn.account/proj1/trunk "https://my.svn.account/proj1/branches/test_branch" -m "testing branch tool"
svn copy https://my.svn.account/proj2/trunk "https://my.svn.account/proj2/branches/test_branch" -m "testing branch tool"
However SVN isn't actually running - the .bat file just loops through quickly printing the commands, and nothing happens.
If I copy-paste the output from each line written to the console and run them individually, they work as expected
Comments on using ugly DOS hacking scripts aside, what's the bug? It fails the same with even one input project name, e.g running:
branchTool test_branch "testing branch tool" proj1
I'm assuming its something to do with your use of the caret character. I've always avoided using it - but can't remember the reason why ....
I'd suggest trying braces instead. E.g.:
@for %%X in (%~3) do (
svn copy https://my.svn.account/%%X/trunk "https://my.svn.account/%%X/branches/%~1" -m "%~2"
)
You could also break the command apart for better legiblity/maintainabilty. I've always prefered assigning numbered parameters to named environment variables. You can then make the intent of the parameters obvious to a later reader of your script. (I usually wrap any environment variable usage in a startlocal/endlocal pair to ensure I don't pollute the callers environment with my temporary variables. E.g.:
setlocal
for %%X in (%~3) do (
set SRC=https://my.svn.account/%%X/trunk
set DST=https://my.svn.account/%%X/branches/%~1
svn copy "%SRC%" "%DST" -m "%~2"
)
endlocal
You might try specifying the fully qualified path to the svn executable, for example C:\path\to\Subversion\svn.exe. It could be that the svn executable is not on environment's path when you execute the batch script.
精彩评论